Sign in to follow this  

[PHP] truncating a string after a substring

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this