我有这个网址如何在php中解析url?
$url = "http://www.google.pt/this/other/that/file.php";
现在我想获得价值这
www.google.pt/ 这 /other/that/file.php
$first_after_root = "this";
$rest_after_this ="other/that/file.php";
我试过用过var_dump(parse_url($url));
我有这个网址如何在php中解析url?
$url = "http://www.google.pt/this/other/that/file.php";
现在我想获得价值这
www.google.pt/ 这 /other/that/file.php
$first_after_root = "this";
$rest_after_this ="other/that/file.php";
我试过用过var_dump(parse_url($url));
此解决方案是关于阵列的爆炸/内爆元素。我鼓励你在每一步打印变量以查看中间体步骤。
// Get the path
$parsed_url = parse_url($url);
$path = $parsed_url['path'];
// Explode path and remove empty elements
$parts = array_filter(explode('/', $path));
// Extract the first element of the $parts array
$first_after_root = array_shift($parts);
// Assign the other elements
$rest_after_this = implode('/', $parts);
我不知道如何得到它的价值,但修复了我 –
非常感谢AlexandreLeprêtre –
['parse_url()'](http://php.net/manual/en/function.parse-url.php)如果您想更详细地处理路径,你应该手动执行此操作。 – NDM
我读过我可以使用类似 $ first_after_root = Explode('/',$ url); –
尝试'var_dump(explode('/',parse_url($ url,PHP_URL_PATH)));' – NDM