可能重复:
在PHP中从URL解析域
如何得到
http://localhost/
Run Code Online (Sandbox Code Playgroud)
从
http://localhost/something/
Run Code Online (Sandbox Code Playgroud)
用php
我试过了
$base = strtok($url, '/');
Run Code Online (Sandbox Code Playgroud)
您可以使用parse_url来获取主机名.
例如:
$url = "http://localhost/path/to/?here=there";
$data = parse_url($url);
var_dump($data);
/*
Array
(
[scheme] => http
[host] => localhost
[path] => /path/to/
[query] => here=there
)
*/
Run Code Online (Sandbox Code Playgroud)
$url = 'http://localhost/something/';
$parsedurl = parse_url($url);
echo $parsedurl['scheme'].'://'.$parsedurl['host'];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14132 次 |
| 最近记录: |