我有像
这样的网址 https://example.com/something/this-is-my-part/10448887
并希望拥有
this-is-my-part
只。
这有选择吗?
答案 0 :(得分:0)
这样的事情应该有效:
$path = parse_url($url, PHP_URL_PATH);
$parts = explode('/', $path);
$part = $parts[count($parts) - 2];
答案 1 :(得分:0)
不确定
$url = "https://example.com/something/this-is-my-part/10448887";
$path = parse_url($url, PHP_URL_PATH);
$segments = explode("/", $path);
echo $segments[2];
答案 2 :(得分:0)
// Remove final slash if it exists
$string = rtrim($string, '/');
// Explode the string into an array
$parts = explode('/', $string);
// Echo 2nd to last item
echo $parts[count($parts) - 2];