Is there a php string function to trim a string after a particular character. I had a look on the php.net site and did a google search but couldn\'t find anything. The only
The strstr
and stristr
functions finds the first occurrence in a string and returns everything after it (including the search string). But it you supply true
as the third argument, it brings back everything in front of the search string.
$string = strstr( $string, '?', true); # Returns /gallery/image
If the match is not found it returns FALSE
so you could write an error check like this:
if( $path = strstr( $string, '?', true) ){
# Do something
}