How to get the site name from URL in PHP?

This question already has an answer here:

  • Get the full URL in PHP 28 answers

  • <?php
    echo $_SERVER['HTTP_HOST'];
    ?>
    

    使用此代码


    $protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
    $url = $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    

    $address = 'http://yoursite.com/';
    echo parse_url($address)['host'];
    
    链接地址: http://www.djcxy.com/p/42282.html

    上一篇: 获取完整的网站网址?

    下一篇: 如何从PHP中的URL获取网站名称?