remove specific chars at end of string

St_Aug_Beach_Bum
St_Aug_Beach_Bum used Ask the Experts™
on
I need to remove specific characters at the end of a string.  But if the string of characters are not there at the end, whatever is there should be left alone.

$str = "<p>this is a test</p><p>and this is another</p>";

and I need to remove the last </p> (but leave the others intact).

I tried:

$trimmed = rtrim(get_the_content(),"</p>");

but it stripped out all the "</p>"'s not just the last.

Suggestions?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
Interesting.  Please show us the test data that came from get_the_content() and I'll try to get you a solution.  It might be a trim() plus a REGEX that looks for a substring at the end of a string, but a test data set will be very helpful to ensure that the solution you get is the best.

Author

Commented:

Ah - you solved it with another question - asking me for the data from get_the_content (a wordpress thing).

I found that get_the_content strips tags. I thought it returned the string with the same content as the_content. But it doesn't.

Thanks, that solves the issue :) I found a wordpress function that returns it with the formatting intact, that should do the trick!  ( http://www.web-templates.nu/2008/08/31/get_the_content-with-formatting/ )
Most Valuable Expert 2011
Top Expert 2016

Commented:
Cool!  Data visualization is a powerful tool.  All the best, big dog! ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial