get host from url

    0

    0

    jvit
    JVIT PHP

    get valid host

    Shortcut: url.host

    /**
    * Returns the host part of any valid URL.
    *
    * @param string $url  Any fully qualified URL
    * @return string|null The actual host in lower case or null if $url is not a valid fully qualified URL.
    */
    function getHostFromUrl($url)
    {
      if (!is_string($url)) {
        return null;
      }
    
      $urlHost = parse_url($url, PHP_URL_HOST);
    
      if (empty($urlHost)) {
        return null;
      }
    
      return mb_strtolower($urlHost);
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.