• Advertisement
Sign in to follow this  

[PHP] truncating a string after a substring

This topic is 4914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I have a nice happy string, and I want to cut it short. I want to have everything up to and including the first instance of "</p>" in the string.
substr($content, 0, strpos($content, '</p>')) . '</p>'
should do the trick, but passing 0 as length to substr is not documented (in case there isn't a '</p>' in $content). On top of that, I don't know if I've made a fencepost error or not. If someone could try this out and get back to me; I'm currently busy debugging SQL in the script.

Share this post


Link to post
Share on other sites
Advertisement
Never mind. Turns out a 0 is treated as a positive number, so I got nothing. Had to use an if statement to check if the para close was in there. Works, though, and nicely.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement