8

How i can get a hash or any text from URL after the question mark. For example "http://mediafire.com/?lmle92c5l50uuy5" I want to get the hash "lmle92c5l50uuy5"

2 Answers 2

9

Try $_SERVER superglobal if you want to get "hash" for current URL:

echo $_SERVER['QUERY_STRING'];

If you really need to parse not your URL, you might also use strstr() + ltrim():

$url = "http://mediafire.com/?lmle92c5l50uuy5";

echo ltrim(strstr($url, '?'), '?');

Shows:

lmle92c5l50uuy5

Also possible to use explode() (as mentioned in @Shubham's answer), but make it shorter with list() language construction:

$url = "http://mediafire.com/?lmle92c5l50uuy5";

list(, $hash) = explode('?', $url);

echo $hash;
Sign up to request clarification or add additional context in comments.

1 Comment

A Q from 2013, this answer is still relevant in 2022, for ordering listings on headers in my case. Will use it all over the place from now on!
4

Use explode().

$arr = explode("?", "http://mediafire.com/?lmle92c5l50uuy5");
$hash = $arr[1];

Or,

You can use parse_url() too.

$hash = parse_url("http://mediafire.com/?lmle92c5l50uuy5", PHP_URL_QUERY);

Comments

Your Answer

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