我有以下 php 变量
$currentUrl
这个 php 变量返回我当前的 url 页面。例如:它返回:
http://example.com/test-category/page.html?_ore=norn&___frore=norian
我可以使用什么 php 代码来获取此 url 链接并删除“之后的所有内容”.html" 并会返回给我一个干净的 url 链接,例如:
http://example.com/test-category/page.html
这将在新变量中返回$clean_currentUrl
With PHP's 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
)
*/
?>
然后您可以根据这些值构建您想要的 url。
$clean_url = $url['scheme'].'://'.$url['host'].$url['path'];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)