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
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;
1 Comment
KJS
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!
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);