Php trim string at a particular character

php, string

Solution

You could use explode:

$string = "/gallery/image?a=b";
list($url,$querystring) = explode('?', $string, 2);

Problem

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 solution I could think of was explode and then grab the first part of the array but that's not the most elegant solution. For example ``` $string = "/gallery/image?a=b"; $string = imaginary_function($string,'?'); echo $string; //echoes "/gallery/image" ``` Does anyone know of a good cheat sheet for php string manipulation functions? Thanks

Original source