PHPCodeIgniter intercepts data

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.