PHP - Get path minus root

橙三吉。 提交于 2020-01-26 02:48:59

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!