How does php get the hostname of the current domain name?

how does php get the hostname of the current domain name?

for example, there is a url: http://m.news.example.com:1000/test/helloworld.php

.

use $_ SERVER ["SERVER_NAME"]; to get the current domain name (without port number), that is, m.news.example.com .
use $_ SERVER ["HTTP_HOST"]; to get the current domain name (with port number), that is, m.news.example.com:1000 .

question:
I just need the hostname news , how can I get it?

Php
Mar.09,2021

echo explode('.',$_SERVER['SERVER_NAME'])[1];
Menu