joe dacoolguy
joe dacoolguy

Reputation: 309

How to turn link to string in PHP

I am just beginning PHP and I am very confused

say

www.blablabla.com/phpfile.php?=this_is_a_test

I want to create a new string from text after the ?=

So in this case the string would be "this_is_a_test"

how would I do this?

Upvotes: 2

Views: 97

Answers (3)

Expedito
Expedito

Reputation: 7805

Use parse_url:

$parsed = parse_url($url);
echo substr($parsed['query'], 1);

Output:

this_is_a_test

If you have multiple variables in the query, you can parse them like in the following example:

$url = 'www.blablabla.com/phpfile.php?foo=bar&baz=boom';
$parsed = parse_url($url);
parse_str($parsed['query'], $out);
print_r($out);

Output:

Array
(
    [foo] => bar
    [baz] => boom
)

Upvotes: 1

Alireza
Alireza

Reputation: 5673

Maybe you need to use $query = $_SERVER['QUERY_STRING'];

Upvotes: 0

Erman Belegu
Erman Belegu

Reputation: 4079

Here is the example:

$url = 'www.blablabla.com/phpfile.php?=this_is_a_test';

print_r(parse_url($url));

Upvotes: 2

Related Questions