I have this string in PHP:
$string = "8470593,3015500750,3148212797";
What I need is to return the first two codes ( 8470593,3015500750
) and discard the rest of the characters.
I know that I need the second occurrence of the comma to be detected ","
, but I can't find a way to do it.
I can propose 2 alternatives:
One with
substr()
andstrrpos()
:This returns:
The other with
strrev()
andstrstr()
:This returns:
I hope it is what you are looking for, greetings.
You can use
explode()
like this: