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
Maybe something like this:
$string = substr($string, 0, strpos($string, '?'));
Note that this isn't very robust (i.e. no error checking, etc), but it might help you solve your problem.
Although pure string functions may give better performance, this is not just a string; it's a URI. Therefore it makes more sense to use a function that's made to handle such data:
echo parse_url("/gallery/image?a=b", PHP_URL_PATH);
// Output: /gallery/image
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With