简体   繁体   English

从URL获取路径

[英]Get path from URL

Looking for a way of getting the path from an URL in PHP: 寻找一种从PHP中的URL获取路径的方法:

I want to take: http://example.com/hurrdurr 我想采取: http://example.com/hurrdurrhttp://example.com/hurrdurr

And make it: hurrdurr 并且做到: hurrdurr

I only want the text after .com/ 我只想要.com/之后的文字

Can i do this with trim? 我可以用修剪来做到这一点吗?

Use parse_url to extract the information you want. 使用parse_url提取所需的信息。

For instance: 例如:

$url = "http://twitter.com/pwsdedtch";
$path = parse_url($url, PHP_URL_PATH); // gives "/pwsdedtech"
$pathWithoutSlash = substr($path, 1); // gives "pwsdedtech"

For this particular case you could also use "basename" for your purposes. 对于这种特殊情况,您也可以使用“basename”来达到目的。

$var='http://twitter.com/pwsdedtch';    
echo basename($var);
// pwsdedtech

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM