CI_Form_validation::valid_url PHP Method

valid_url() public method

Valid URL
public valid_url ( string $str ) : boolean
$str string
return boolean
    public function valid_url($str)
    {
        if (empty($str)) {
            return FALSE;
        } elseif (preg_match('/^(?:([^:]*)\\:)?\\/\\/(.+)$/', $str, $matches)) {
            if (empty($matches[2])) {
                return FALSE;
            } elseif (!in_array($matches[1], array('http', 'https'), TRUE)) {
                return FALSE;
            }
            $str = $matches[2];
        }
        // PHP 7 accepts IPv6 addresses within square brackets as hostnames,
        // but it appears that the PR that came in with https://bugs.php.net/bug.php?id=68039
        // was never merged into a PHP 5 branch ... https://3v4l.org/8PsSN
        if (preg_match('/^\\[([^\\]]+)\\]/', $str, $matches) && !is_php('7') && filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) {
            $str = 'ipv6.host' . substr($str, strlen($matches[1]) + 2);
        }
        $str = 'http://' . $str;
        // There's a bug affecting PHP 5.2.13, 5.3.2 that considers the
        // underscore to be a valid hostname character instead of a dash.
        // Reference: https://bugs.php.net/bug.php?id=51192
        if (version_compare(PHP_VERSION, '5.2.13', '==') or version_compare(PHP_VERSION, '5.3.2', '==')) {
            sscanf($str, 'http://%[^/]', $host);
            $str = substr_replace($str, strtr($host, array('_' => '-', '-' => '_')), 7, strlen($host));
        }
        return filter_var($str, FILTER_VALIDATE_URL) !== FALSE;
    }