user2796274
user2796274

Reputation:

PHP get hash after question mark

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"

Upvotes: 8

Views: 8329

Answers (2)

BlitZ
BlitZ

Reputation: 12168

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;

Upvotes: 9

Shubham
Shubham

Reputation: 22317

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);

Upvotes: 4

Related Questions