从 URL 获取路径 [英] Get path from URL
本文介绍了从 URL 获取路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
寻找一种从 PHP 中的 URL 获取路径的方法:
Looking for a way of getting the path from an URL in PHP:
我想拿:http://example.com/hurrdurr
并做到:hurrdurr
我只想要.com/
我可以用修剪来做到这一点吗?
Can i do this with trim?
推荐答案
使用 parse_url
提取你想要的信息.
Use parse_url
to extract the information you want.
例如:
$url = "http://twitter.com/pwsdedtch";
$path = parse_url($url, PHP_URL_PATH); // gives "/pwsdedtech"
$pathWithoutSlash = substr($path, 1); // gives "pwsdedtech"
这篇关于从 URL 获取路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文