Domanda

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.

So example of url would be something like this.

http://somesite.com/uploaded/images/8.jpg?m=eSuQKgaaaa&mh=t0i7nVhjZleTJ5Ih

So this content behind question mark is some sort of the code that makes images resized to small size.

If i would just take this

http://somesite.com/uploaded/images/8.jpg

Images would be in bigger resolution and that's what i need.

I know there is a function like preg_match but i never understood expressions in it.

Is it possible that i somehow remove questionmark and all the content behind it ?

È stato utile?

Soluzione

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.

Altri suggerimenti

In a much easier way it could be:

$iWantThisURL = substr($curr_url(), 0, stripos($curr_url, '?'));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top