Home  >  Article  >  Backend Development  >  如何获取主机头在页面中显示?

如何获取主机头在页面中显示?

WBOY
WBOYOriginal
2016-06-23 13:42:43803browse

列:
打开http://111.xxx.com/index.php在当前页面中只显示“ 111”
如果打开的是http://2893.xxx.com/index.php 页面中显示的是” 2893“
这个用什么代码获取呢?


回复讨论(解决方案)

print_r($_SERVER);

$host=$_SERVER["HTTP_HOST"];
preg_match('/[^.]+/',$host,$mat);
echo $mat[0];

或者
$host=$_SERVER["HTTP_HOST"];
$hostarr=explode('.',$host);
echo $hostarr[0];

echo strtok($_SERVER["HTTP_HOST"], '.');

echo explode('.',$_SERVER['HTTP_HOST'])[0];

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn