check valid url

    0

    0

    JVIT PHP

    check valid url

    Shortcut: url.isValid

    /**
    * Returns true if the string passed may be a URL ie. it starts with protocol://.
    *
    * @param string $url
    * @return bool
    */
    function isValidUrl(string $url)
    {
      return $url && preg_match('~^(([[:alpha:]][[:alnum:]+.-]*)?:)?//(.*)$~D', $url, $matches) !== 0
        && strlen($matches[3]) > 0
        && !preg_match('/^(javascript:|vbscript:|data:)/i', $matches[1]);
    }
    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.