我有以下php变量
$currentUrl
Run Code Online (Sandbox Code Playgroud)
这个php变量返回当前的url页面.例如:它返回:
http://example.com/test-category/page.html?_ore=norn&___frore=norian
Run Code Online (Sandbox Code Playgroud)
我可以使用哪些PHP代码将获取此URL链接并删除" .html " 之后的所有内容,并将返回一个干净的URL链接,例如:
http://example.com/test-category/page.html
Run Code Online (Sandbox Code Playgroud)
这将在新变量$ clean_currentUrl中返回
Law*_*one 13
用PHP的 parse_url()
<?php
$url = "http://example.com/test-category/page.html?_ore=norn&___frore=norian";
$url = parse_url($url);
print_r($url);
/*
Array
(
[scheme] => http
[host] => example.com
[path] => /test-category/page.html
[query] => _ore=norn&___frore=norian
)
*/
?>
Run Code Online (Sandbox Code Playgroud)
然后,您可以从值构建所需的URL.
$clean_url = $url['scheme'].'://'.$url['host'].$url['path'];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1610 次 |
最近记录: |