0

I would like to get parameter from variable that holds URL.
I got the following variable: $lastPage that holds the URI of the previous page.

I would like to get a parameter from it.
I got the following script in javascript (which I use for something else)

function getUrlVar(key)
{
    var result = new RegExp(key + '=([^&]*)', 'i').exec(window.location.search);
    return result && unescape(result[1]) || '';
}

I want something like that but for PHP.

Thank you very much

2 Answers 2

6
$url = 'http://php.net/manual/en/function.parse-url.php?id=my_awesome_id';
$arr = parse_url($url);
parse_str($arr['query']);
echo $id; // my_awesome_id

Reference:

parse_str

parse_url

Sign up to request clarification or add additional context in comments.

Comments

0

You can use preg_match() or preg_match_all() in php which will give you the regular expression functionality.

http://php.net/manual/en/function.preg-match.php

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.