问题
So I have this link:
http://kenthomes.net/Amelia-Cove (We use an alias system.)
Then I open a pop-up iframe (http://kenthomes.net/shareplan.php?mod=39)
How I can I pass the string "Amelia-Cove" to that page?
My best guess was to make the link = to http://kenthomes.net/shareplan.php?mod=39&plan=Amelia-Cove
But how to I retrieve only "Amelia-Cove" from the initial page?
回答1:
Try this:
$_SERVER['REQUEST_URI']
In your above example, this would have a value of: /Amelia-Cove
. If you want to get rid of the /
, try this:
trim($_SERVER['REQUEST_URI'],'/');
回答2:
You can use the GET protocol to receive parameters in the URL:
http://kenthomes.net/shareplan.php?mod=39&plan=Amelia-Cove
then fetch these parameters through the PHP GET global variable:
$_GET['plan']
回答3:
I'm assuming OP will not always fetch Amelia-Cove but rather want that part of the url and used Amelia-Cove as an example and knows how to use $_GET
To fetch that part of the url and pass it through $_GET I would suggest using this:
parse_url($url, PHP_URL_PATH)
Full parse_url documentation
来源:https://stackoverflow.com/questions/15842455/php-get-path-minus-root