开发者

Get path from URL

开发者 https://www.devze.com 2023-01-13 12:40 出处:网络
Looking for a way of getting the path from an URL in PHP: I want to take: http://example.开发者_JAVA百科com/hurrdurr

Looking for a way of getting the path from an URL in PHP:

I want to take: http://example.开发者_JAVA百科com/hurrdurr

And make it: hurrdurr

I only want the text after .com/

Can i do this with trim?


Use parse_url to extract the information you want.

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.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号