?
Solved

strpos() but starting from end then delete the last word + the comma at end PHP

Posted on 2009-04-16
3
Medium Priority
?
886 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:Victor Kimura
  • 2
3 Comments
 
LVL 3

Expert Comment

by:Chimeraza
ID: 24155411
This should work for you...

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
0
 
LVL 3

Accepted Solution

by:
Chimeraza earned 2000 total points
ID: 24155421
Sorry, should be....

<?php
$string = 'rot,h ira c,ontribu,tion';
echo substr($string, 0, mb_strrpos ($string , ','));
?>
0
 

Author Closing Comment

by:Victor Kimura
ID: 31570863
Thanks, Chimeraza. I thought it would be something simple like that.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question