Can someone tell me how to print out a part of the url that the visitor has landed upon? Specifically the part after the question mark. For example, if the visitor has landed on the url:
http://www.url.com/test.html?item=28444 how would I print out just the number 28444?
This is what I know so far. That I could use the parse_url command as follows:
Code: Select all
<?php
$url = parse_url("http://www.url.com/test.html?item=28444");
echo ereg_replace("item=", "", $url["query"]);
?>
This code does print out the number 28444. However, in the above example, I entered the actual url for the $url variable. If I’m going to enter the url myself I might as well use “echo 28444” for the entire code. I think the point for any such code would be to pick off from the url ANY item number, based on the url that the visitor has landed upon (not the url that we have typed ourselves in the code). For example, if the visitor lands on the url:
http://www.url.com/test.html?item=28577 , based on the above code it would still print 28444 because I defined the $url variable myself using
http://www.url.com/test.html?item=28444
So how could it be coded so that this item number section of the url is printed based on whatever URL the visitor is on?