0

How do I use preg_match to get a query string from a URL?

http://www.example.com/imgres?imgurl=http://www.example.com/images/blue-diamond-rings.jpg

How do I get 'imgurl' using preg_matches from the above URL?

1 Answer 1

7

PHP has functions for parsing URLs and query strings, you don't need to use a regular expression.

$parts = parse_url("http://www.mysite.com/imgres?imgurl=http://www.mysite.com/images/blue-diamond-rings.jpg");

$query_string = $parts['query'];

parse_str($query_string, $output);

echo $output['imgurl'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.