Check if a given string looks like it could be a URL, with or without the protocol.

@see https://mathiasbynens.be/demo/url-regex

@param string $str

@return bool
771439
public static function isURL($str)
    {
        $pattern = '~^(?:\b[a-z\d.-]+://[^<>\s]+|\b(?:(?:(?:[^\s!@#$%^&*()_=+[\]{}\|;:\'",.<>/?]+)\.)+(?:ac|ad|aero|ae|af|ag|ai|al|am|an|ao|aq|arpa|ar|asia|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|biz|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|cat|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|coop|com|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|info|int|in|io|iq|ir|is|it|je|jm|jobs|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mobi|mo|mp|mq|mr|ms|mt|museum|mu|mv|mw|mx|my|mz|name|na|nc|net|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|travel|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xn--0zwm56d|xn--11b5bs3a9aj6g|xn--80akhbyknj4f|xn--9t4b11yi5a|xn--deba0ad|xn--g6w251d|xn--hgbk6aj7f53bba|xn--hlcj6aya9esc7a|xn--jxalpdlp|xn--kgbechtv|xn--zckzah|ye|yt|yu|za|zm|zw)|(?:(?:[0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:[0-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]))(?:[;/][^#?<>\s]*)?(?:\?[^#<>\s]*)?(?:#[^<>\s]*)?(?!\w))$~iS';

        // Special case that isn't caught by this regex: 'http://' or 'https://' without a domain.
        if (preg_match('~^https?://$~i', $str)) {
            return false;
        }

        return (bool) preg_match($pattern, $str . '/');
    }
931584
function _filter_uri($str)
	{
		if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
		{
			// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
			// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
			if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
			{
				show_error('The URI you submitted has disallowed characters.', 400);
			}
		}

		// Convert programatic characters to entities
		$bad	= array('$',		'(',		')',		'%28',		'%29');
		$good	= array('&#36;',	'&#40;',	'&#41;',	'&#40;',	'&#41;');

		return str_replace($bad, $good, $str);
	}
1286867
public static function xml(string $str) : bool
    {
        $initialSetting = libxml_use_internal_errors();
        libxml_use_internal_errors(true);
        $result = simplexml_load_string($str) !== false;
        libxml_use_internal_errors($initialSetting);

        return $result;
    }
576695
public static function isSlug($str)
    {
        if (!is_string($str)) {
            throw new \ErrorException('Accept string ' . gettype($str) . ' given');
        }

        return  (bool) preg_match('/^[a-z0-9-]+[a-z0-9]+$/', $str);
    }
380468
public static function isTagged(string $str): bool
    {
        return isset($str[1]) && strpos($str, '@') === 0 && ctype_alpha($str[1]);
    }
187177
private function _decode_string(string $str): string
    {
        // init
        $regExForHtmlTags = '/<\p{L}+.*+/us';

        if (
            \strpos($str, '<') !== false
            &&
            \preg_match($regExForHtmlTags, $str, $matches) === 1
        ) {
            $str = (string) \preg_replace_callback(
                $regExForHtmlTags,
                function ($matches) {
                    return $this->_decode_entity($matches);
                },
                $str
            );
        } else {
            $str = UTF8::rawurldecode($str);
        }

        return $str;
    }
420765
protected function hasDelimiterToArray($str)
    {
        if ( is_string($str) && preg_match('/[,|]/is', $str) ) {
            return preg_split('/ ?[,|] ?/', strtolower($str));
        }

        return is_array($str) ? 
            array_filter($str, 'strtolower') : 
            (is_object($str) ? $str : strtolower($str));
    }
618762
protected function _stringHasR($str) {
		foreach (func_get_args() as $arg) {
			if (strpos($arg, "\r") !== false) {
				return true;
			}
		}
		return false;
	}
484044
public static function isURL(string $url): bool {
        return (boolean) !(filter_var($url, FILTER_SANITIZE_URL | FILTER_VALIDATE_URL) === false);
    }
1008919
public static function safe($str)
    {
        if(is_array($str)){
            foreach($str as $key=>$val){
                $str[$key] = self::safe($val);
            }
            return $str;
        }
        return htmlspecialchars($str, ENT_QUOTES);
    }
540099
protected function _validate_entities($str) {
		/*
		 * Protect GET variables in URLs
		 */
		
		// 901119URL5918AMP18930PROTECT8198
		
		$str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash() . "\\1=\\2", $str);
		
		/*
		 * Validate standard character entities Add a semicolon if missing. We
		 * do this to enable the conversion of entities to ASCII later.
		 */
		$str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str);
		
		/*
		 * Validate UTF16 two byte encoding (x00) Just as above, adds a
		 * semicolon if missing.
		 */
		$str = preg_replace('#(&\#x?)([0-9A-F]+);?#i', "\\1\\2;", $str);
		
		/*
		 * Un-Protect GET variables in URLs
		 */
		$str = str_replace($this->xss_hash(), '&', $str);
		
		return $str;
	}
1317951
protected function isRegex($str)
    {
        if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
            $start = substr($m[1], 0, 1);
            $end = substr($m[1], -1);

            if ($start === $end) {
                return !preg_match('/[*?[:alnum:] \\\\]/', $start);
            }

            foreach ([['{', '}'], ['(', ')'], ['[', ']'], ['<', '>']] as $delimiters) {
                if ($start === $delimiters[0] && $end === $delimiters[1]) {
                    return true;
                }
            }
        }

        return false;
    }
511792
public static function isSymbol($str)
    {
        if (strlen($str) === 0) {
            return null;
        }
        if ($str[0] === '@') {
            return Token::FLAG_SYMBOL_VARIABLE;
        } elseif ($str[0] === '`') {
            return Token::FLAG_SYMBOL_BACKTICK;
        } elseif ($str[0] === ':') {
            return Token::FLAG_SYMBOL_PARAMETER;
        }

        return null;
    }
431416
static private function ContainsSpace( 
                            string $str
    ) : bool {		
    
        $ret = false;
    
        for ( $i = 0; $i < strlen( $str ); $i++ ) {
            if ( ctype_space( substr( $str, $i, 1 ) ) ) {
                $ret = true;
                break;
            }
        }
        
        return $ret;
    
    }
1147713
public static function isRelative(string $url): bool
  {
    if ($url!=='')
    {
      return ((mb_substr($url, 0, 1)=='/' &&
          (mb_strlen($url)==1 || (mb_substr($url, 1, 1)!='/' && mb_substr($url, 1, 1)!='\\'))) ||
        (mb_strlen($url)>1 && mb_substr($url, 0, 2)=='~/'));
    }

    return false;
  }
382106
public static function isTraditional($str) {
    if (empty($str)) {
      throw new Exception('Argument str cannot be empty');
    }
    $ords = self::utf8ToUnicode($str);
    foreach ($ords as $val) {
      if (!empty($val) && array_key_exists($val, self::$trad2simple)) {
        return true;
      }
    }
    return false;
  }
1318094
protected function _auto($str) {
		$self=$this;
		return preg_replace_callback(
			'/`.*?<(.+?)>.*?`|<(.+?)>/',
			function($expr) use($self) {
				if (empty($expr[1]) && parse_url($expr[2],PHP_URL_SCHEME)) {
					$expr[2]=$self->esc($expr[2]);
					return '<a href="'.$expr[2].'">'.$expr[2].'</a>';
				}
				return $expr[0];
			},
			$str
		);
	}