Generate a URL friendly "slug" from a given string.

@param string $str

@return string
511483
private function slug($str)
    {
        // replace non letter or digits by -
        $str = preg_replace('~[^\\pL\d]+~u', '-', $str);

        $str = trim($str, '-');

        // transliterate
        $str = iconv('utf-8', 'us-ascii//TRANSLIT', $str);

        $str = strtolower($str);

        // remove unwanted characters
        $str = preg_replace('~[^-\w]+~', '', $str);

        return $str;
    }
618893
protected function modifyHost(string $str): string
    {
        return (string) $this->filterHost($str, $this->resolver)->withSubDomain($this->label);
    }
479136
protected function modifyPath(string $str): string
    {
        return (string) $this->filterSegment($str)->prepend($this->segment);
    }
122875
public function token($str) {
        $str=trim(preg_replace('/\{\{(.+?)\}\}/s',trim('\1'),
            Base::instance()->compile($str)));
        if (preg_match('/^(.+)(?<!\|)\|((?:\h*\w+(?:\h*[,;]?))+)$/s',
            $str,$parts)) {
            $str=trim($parts[1]);
            foreach (Base::instance()->split($parts[2]) as $func)
                $str=is_string($cmd=$this->filter($func))?
                    $cmd.'('.$str.')':
                    'Base::instance()->'.
                    'call($this->filter(\''.$func.'\'),['.$str.'])';
        } elseif (false !== strpos($str, '(')) {
            for ($i=0,$len=strlen($str),$newStr='',$tmp='';$i<$len;) {
                if ($str[$i] === '(') {
                    if ($tmp && array_key_exists($tmp, $this->filter)) {
                        $tmp = $this->filter[$tmp];
                    }
                    $newStr .= $tmp . '(';
                    $tmp = '';
                } elseif (in_array($str[$i], [' '])) {
                    $newStr .= $tmp . $str[$i];
                    $tmp = '';
                } else {
                    $tmp .= $str[$i];
                }
                $i++;
            }
            $newStr .= $tmp;
            $str = $newStr;
        }

        return $str;
    }
1047107
private function _filter_uri($str)
	{
		if ($str != '' && $this->getConfig('permitted_uri_chars') != '' && $this->getConfig('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->getConfig('permitted_uri_chars'), '-'))."]+$|i", $str))
			{
				Exceptions::showError('Server Error','The URI you submitted has disallowed characters.');
			}
		}

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

		return str_replace($bad, $good, $str);
	}
835641
static public function fromCamel($str) {
      $str[0] = strtolower($str[0]);
      return preg_replace_callback('/([A-Z])/', function($char) {return "_" . strtolower($char[1]);}, $str);
  }
38541
private function escapeLikeString($str)
    {
        if (false !== strpos($str, '%')) {
            $str = str_replace("%", "\%", $str);
        }

        if (false !== strpos($str, '_')) {
            $str = str_replace("_", "\_", $str);
        }
        
        return $str;
    }
1279817
public static function getString(&$str)
    {
        $p = strpos($str, "\x00");
        if ($p === false) {
            return '';
        }
        $r   = static::binarySubstr($str, 0, $p);
        $str = static::binarySubstr($str, $p + 1);

        return $r;
    }
467593
public static function replaceRoman(string $str) : string
    {
        $str = self::strToArray($str);
        return implode('', self::replaceRomanArray($str));
    }
745939
public static function fromString(string $str) : Cookie
    {
        $err = false;
        $name = "";
        $value = "";
        $expires = null;
        $domain = null;
        $path = "/";
        $secure = false;
        $httpOnly = false;


        if ($str === "") {
            $err = "The string is not a valid representation of a cookie.";
        }


        if ($err === false) {
            $parts = array_map("trim", explode(";", $str));

            $nameValue = explode("=", $parts[0]);

            $name = $nameValue[0];
            $value = ((count($nameValue) === 2) ? $nameValue[1] : "");

            if (count($parts) > 1) {
                array_shift($parts);

                foreach ($parts as $p) {
                    $keyPair = array_map("trim", explode("=", $p));
                    if (count($keyPair) === 1) {
                        $keyPair[] = null;
                    }

                    $val = $keyPair[1];

                    switch (strtolower($keyPair[0])) {
                        case "expires":
                            if ($val !== null) {
                                if (is_numeric($val) === true) {
                                    $expires = new \DateTime();
                                    $expires->setTimestamp((int)$val);
                                } else {
                                    if (strpos(strtolower($val), " utc") !== false ||
                                        strpos(strtolower($val), " gmt") !== false) {
                                        $val = substr($val, 0, strlen($val) - 4);
                                    }
                                    $expires = \DateTime::createFromFormat("D, d M Y H:i:s", $val);
                                }
                            }
                            break;

                        case "domain":
                            $domain = $val;
                            break;

                        case "path":
                            $path = $val;
                            break;

                        case "secure":
                            $secure = true;
                            break;

                        case "httponly":
                            $httpOnly = true;
                            break;
                    }
                }
            }
        }


        if ($err === false) {
            return new Cookie($name, $value, $expires, $domain, $path, $secure, $httpOnly);
        } else {
            throw new \InvalidArgumentException($err);
        }
    }
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 . '/');
    }
662632
private function toNamespace($str) {
        $stringParts = preg_split('/_+/', $str);

        foreach($stringParts as $key => $stringPart){
            $stringParts[$key] = ucfirst(strtolower($stringPart));
        }
        return implode('\\', $stringParts) . '\\';
    }
171126
public static function encode(String $str) : String
    {
        $chars = self::$numericalCodes;

        return str_replace(array_keys($chars), array_values($chars), $str);
    }
1123770
protected function modifyPath(string $str): string
    {
        return (string) $this->filterSegment($str)->replaceSegment($this->offset, $this->segment);
    }
1362597
protected function toupper($str)
    {
        // string can contain HTML tags
        $chunks = preg_split('/(<[^>]*>)/', $str, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

        // convert toupper only the text between HTML tags
        foreach ($chunks as $i => $chunk) {
            if ($chunk[0] != '<') {
                $chunks[$i] = $this->strtoupper($chunk);
            }
        }

        return implode($chunks);
    }
36234
public static final String slugify(final String str) {
      StringBuilder buf = new StringBuilder();
      boolean lastWasDash = false;
      for(char ch : str.toLowerCase().trim().toCharArray()) {
         if(Character.isLetterOrDigit(ch)) {
            buf.append(ch);
            lastWasDash = false;
         } else {
            if(!lastWasDash) {
               buf.append("-");
               lastWasDash = true;
            }
         }
      }

      String slug = buf.toString();
      if(slug.length() == 0) {
         return "";
      }

      if(slug.charAt(0) == '-') {
         slug = slug.substring(1);
      }
      if(slug.length() > 0 && slug.charAt(slug.length() - 1) == '-') {
         slug = slug.substring(0, slug.length() - 1);
      }

      return slug;
   }
751516
protected function fromCamelCase($str)
    {
        $func = function ($str) {
            return ' '.$str[0];
        };

        $value = preg_replace_callback('/([A-Z])/', $func, $str);
        $value = ucfirst($value);

        return trim($value);
    }