简体中文
在PHP中,可以通过内置函数 gethostname() 获取当前服务器的主机名。该函数会返回一个字符串,包含当前计算机的主机名,例如:"当前主机名:my-computer"。
使用 gethostname() 函数可以轻松获取主机名。这个函数不需要额外参数,直接调用即可。
<?php $hostname = gethostname(); echo "当前主机名:$hostname"; ?>
当前主机名:my-computer
gethostname() 函数执行以下操作: