Solution:1
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.
Solution:1
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.
Solution:2
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
}