Victor Kimura
asked on
strpos() but starting from end then delete the last word + the comma at end PHP
Hi,
I'm trying to find the position of the last "," (comma) in this list:
roth ira contribution,ira contribution limits,traditional ira,roth ira,excess contributions,simple ira
then delete the last comma till the end of the list so the word list will look like:
roth ira contribution,ira contribution limits,traditional ira,roth ira,excess contributions
I was looking at strpos() but that won't work as this list will vary in length.
Thank you,
vkimura
I'm trying to find the position of the last "," (comma) in this list:
roth ira contribution,ira contribution limits,traditional ira,roth ira,excess contributions,simple ira
then delete the last comma till the end of the list so the word list will look like:
roth ira contribution,ira contribution limits,traditional ira,roth ira,excess contributions
I was looking at strpos() but that won't work as this list will vary in length.
Thank you,
vkimura
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, Chimeraza. I thought it would be something simple like that.
mb_strrpos will give you the last position of the ','
substr will truncate the string from position 0 to the position of the ','
<?php
$string = 'rot,h ira c,ontribu,tion';
echo substr($haystack, 0, mb_strrpos ($string , ','));
?>
Kind regards
Nick