我想知道如何在?
字符之前获取当前网址:
http://www.example.com/pag1?q=ok
输出:
http://www.example.com/pag1
答案 0 :(得分:4)
你可以将你的网址分解为
$url = 'http://www.example.com/pag1?q=ok';
$explodedURL= parse_url($url);
echo '<pre>';
print_r($explodedURL['host'].explodedURL['path']);
echo $explodedURL['scheme'].'://'.$explodedURL['host'].$explodedURL['path'];
输出:
Array
(
[scheme] => http
[host] => www.example.com
[path] => /pag1
[query] => q=ok
)
http://www.example.com/pag1
答案 1 :(得分:1)
类似的东西:
$url = 'http://www.example.com/pag1?q=ok’;
$pos = strpos($url, '?');
$yourstr = strstr($url, 0, $pos - 1);