This question already has an answer here:
I am new to php. Suppose I have a string variable as followings:
$val="https://www.example.com?id=1001";
Is there any way to get the value of the id part in another variable $id? So I just want to assign 1001 into $id using variable $val; How will I do it?
</div>
Parse the URL to get the query string id=1001
and then parse that to turn it into an array of GET parameters and there values:
parse_str(parse_url($val, PHP_URL_QUERY), $result);
echo $result['id'];
This may seem like overkill for a string, but for variable URLs that may have a lengthy query string it should always work as the functions are designed for this purpose.
If this were the URL of the actual page running the PHP then it is already populated into a super global:
echo $_GET['id'];