Im working on some function to grab few data from url with simple html dom.
But one of the data is an image and image have question mark and some more info behind it
In a much easier way it could be:
$iWantThisURL = substr($curr_url(), 0, stripos($curr_url, '?'));
Even easier: use explode()
:
list($uri,) = explode('?', 'http://somesite.com/uploaded/images/8.jpg?m=eSuQKgaaaa&mh=t0i7nVhjZleTJ5Ih');
update
Or simpler yet use strtok and trim:
$uri = trim(strtok('http://somesite.com/uploaded/images/8.jpg?m=eSuQKgaaaa&mh=t0i7nVhjZleTJ5Ih', '?'));
Normally you would use parse_url()
for working with URLs but in a case like this, using explode()
is simpler to use and serve's your purpose.