PHPCodeIgniter intercepts data
15018903588-006
There is a horizontal bar in the middle. how can we extract the data based on the data in front of the horizontal bar in the middle?
Find the prawn code and paste it
Reply to discussion (solution)
$str = '15018903588-006';$last = substr($str,0,strrpos($str,'-'));$next = substr(strstr($str,'-'),1);echo $last,PHP_EOL;echo $next
$str = '15018903588-006';$last = substr($str,0,strrpos($str,'-'));$next = substr(strstr($str,'-'),1);echo $last,PHP_EOL;echo $next
The following figure shows the data. can I write it like this?
The above result is: 15018903588
---------------------------------------------------------------
It is concluded that: 006
I understand it, right?
$str = '15018903588-006';$last = substr($str,0,strrpos($str,'-'));$next = substr(strstr($str,'-'),1);echo $last,PHP_EOL;echo $next
The following figure shows the data. can I write it like this?
The above result is: 15018903588
---------------------------------------------------------------
It is concluded that: 006
I understand it, right?
Yes
Foreach ($ info as $ key => $ value)
{
?>
Strange values cannot be displayed.
------------------------------------------------------
As shown below:
Foreach ($ info as $ key => $ value)
{
?>
$str = '15018903588-006';$last = substr($str,0,strrpos($str,'-'));$next = substr(strstr($str,'-'),1);echo $last,PHP_EOL;echo $next
The following figure shows the data. can I write it like this?
The above result is: 15018903588
---------------------------------------------------------------
It is concluded that: 006
I understand it, right?
Yes
-------------------------------------------
By the way, some numbers do not have a OEM number. how can we verify the number, for example, if there is no employee number?
$str = '15018903588-006';$last = substr($str,0,strrpos($str,'-'));$next = substr(strstr($str,'-'),1);echo $last,PHP_EOL;echo $next
The following figure shows the data. can I write it like this?
The above result is: 15018903588
---------------------------------------------------------------
It is concluded that: 006
I understand it, right?
Yes
-------------------------------------------
By the way, some numbers do not have a OEM number. how can we verify the number, for example, if there is no employee number?
Determine whether the employee ID exists. if the employee ID exists, it is intercepted. if the employee ID does not exist, it is skipped.
Foreach ($ info as $ key => $ value)
{
?>
Strange values cannot be displayed.
------------------------------------------------------
As shown below:
Foreach ($ info as $ key => $ value)
{
?>
Check whether a value exists.
$ Value ['homa '] = '2017-006 ';
Echo substr ($ value ['homa '], 0, strrpos ($ value ['homa'], '-');
?>
Foreach ($ info as $ key => $ value)
{
?>
Strange values cannot be displayed.
------------------------------------------------------
As shown below:
Foreach ($ info as $ key => $ value)
{
?>
Check whether a value exists.
$ Value ['homa '] = '2017-006 ';
Echo substr ($ value ['homa '], 0, strrpos ($ value ['homa'], '-');
?>
--------------------------------------------------
Some data does not contain employee IDs, for example:
Foreach ($ info as $ key => $ value)
{
?>
Strange values cannot be displayed.
------------------------------------------------------
As shown below:
Foreach ($ info as $ key => $ value)
{
?>
Check whether a value exists.
$ Value ['homa '] = '2017-006 ';
Echo substr ($ value ['homa '], 0, strrpos ($ value ['homa'], '-');
?>
------------------------------------------------------------
$ Value ['homa '] = '123 ';
Echo substr ($ value ['homa '], 0, strrpos ($ value ['homa'], '-');
$ Value ['homa '] = '123 ';
Echo substr ($ value ['homa '], 0, strrpos ($ value ['homa'], '-');
Foreach ($ info as $ key => $ value)
{
?>
Strange values cannot be displayed.
------------------------------------------------------
As shown below:
Foreach ($ info as $ key => $ value)
{
?>
Check whether a value exists.
$ Value ['homa '] = '2017-006 ';
Echo substr ($ value ['homa '], 0, strrpos ($ value ['homa'], '-');
?>
-------------------------------------------
Data value:
15018903588-006
057188888881-007
05718888888-007
15018903588
The preceding values show data of one of them.
What I want to achieve is:
Extract the front and back data of the horizontal bar and directly display the data without the horizontal bar.
Determine whether the employee ID has "-"
If (strpos ($ value ['homa '],'-') {
$ Last = substr ($ value ['homa '], 0, strrpos ($ value ['homa'], '-');
$ Next = substr (strstr ($ value ['homa '],'-'), 1 );
} Else {
$ Value ['homa '];
}
Thank you.