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

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

WBOY
Release: 2016-06-23 13:42:43
Original
956 people have browsed it

列:
打开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"], '.');
Copy after login

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template