Create a slug out of the given string.

Non-alphanumeric characters are converted to hyphens.

@param string $str
@return string
762411
public static function slug($str)
    {
        $str = strtolower($str);
        $str = preg_replace('/[^a-z0-9]/i', '-', $str);
        $str = preg_replace('/-+/', '-', $str);
        $str = preg_replace('/-$|^-/', '', $str);

        return $str;
    }
72984
public static function toString($str){
		$str = strtoupper($str);

		// csSave actually has to be able to consider extra characters
		if(self::$charset === Base32Characters::CROCKFORD){
			$str = str_replace('O', '0', $str);
			$str = str_replace(['I', 'L'], '1', $str);
		}

		return self::bin2str(self::toBin($str));
	}
143366
public static function escapeString(string $str): string
    {
        // one of the characters ",", "+", """, "\", "<", ">" or ";"
        $str = preg_replace('/([,\+"\\\<\>;])/u', '\\\\$1', $str);
        // a space character occurring at the end of the string
        $str = preg_replace('/( )$/u', '\\\\$1', $str);
        // a space or "#" character occurring at the beginning of the string
        $str = preg_replace('/^([ #])/u', '\\\\$1', $str);
        // implementation specific special characters
        $str = preg_replace_callback('/([\pC])/u',
            function ($m) {
                $octets = str_split(bin2hex($m[1]), 2);
                return implode("",
                    array_map(
                        function ($octet) {
                            return '\\' . strtoupper($octet);
                        }, $octets));
            }, $str);
        return $str;
    }
966657
public static function strToHex($str)
	{
		$r = "";
		$l = strlen($str);
		for($i = 0; $i < $l; $i++)
			$r .= str_pad(strtoupper(dechex(ord($str[$i]))), 2, " ",
				STR_PAD_LEFT) . " ";
		return $r;
	}
155170
private function _convert_filename($str)
    {
        $str = strtr($str, array(':' => '', '/' => '-'));

        return rcube_charset::convert($str, RCUBE_CHARSET, $this->charset);
    }
835641
static public function fromCamel($str) {
      $str[0] = strtolower($str[0]);
      return preg_replace_callback('/([A-Z])/', function($char) {return "_" . strtolower($char[1]);}, $str);
  }
551849
public static function formatBankCard($str)
    {
        $str = (string)$str;
        preg_match('/([\d]{4})([\d]{4})([\d]{4})([\d]{4})([\d]{0,})?/', $str, $match);
        unset($match[0]);
        return implode(' ', $match);
    }
29094
private static function utf8ToUnicode($str) {
    $new = array();
    $len = iconv_strlen($str);
    for ($n = 0; $n < $len; $n++) {
      $char = iconv_substr($str, $n, 1);
      $new[] = self::uniord($char);
    }
    return $new;
  }
323617
public static function createSlug(string $str)
    {
        $chpu = trim($str);
        $chpu = self::transliterate($chpu);
        $chpu = str_replace("'", '', $chpu);
        $chpu = str_replace('"', '', $chpu);
        $chpu = str_replace(" ", '-', $chpu);
        $chpu = str_replace(".", '', $chpu);
        $chpu = str_replace(",", '', $chpu);
        $chpu = str_replace("+", '', $chpu);
        $chpu = str_replace("/", '-', $chpu);
        $chpu = str_replace("\\", '-', $chpu);
        $pattern = '|[^A-Za-z0-9ЙФЯЧЫЦУВСМАКЕПИТРНГОЬБЛШЩДЮЖЗХЭЪЁёйфячыцувсмакепитрнгоьблшщдюзжхэъ-]|';
        $chpu = preg_replace($pattern, '', $chpu);
        $chpu = strtolower($chpu);
        $chpu = preg_replace('/[\-]{2,}/', '-', $chpu);
        $chpu = iconv('UTF-8', 'UTF-8//IGNORE', $chpu);
        return $chpu;
    }
737900
public static function str2url($str)
    {
        $str = self::rus2translit($str);
        $str = strtolower($str);
        $str = preg_replace('~[^-a-z0-9_]+~u', '-', $str);
        $str = trim($str, "-");
        return $str;
    }
753765
public function slugify($str = '', $options = NULL)
    {
        try {
            if (!empty($options) && is_array($options)) {
                $slugify = new Slugify($options);
            } else {
                $slugify = new Slugify();
            }

            return $slugify->slugify($str);
        }
        catch (\Exception $e) {
            if (function_exists('log_message')) {
                $message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
                log_message('error', $message);
            }

            return $this->common->convertStrToEn($str);
        }
    }
1202540
public static function encodeIRI( $str )
    {
        $codec = eZTextCodec::instance( false, 'utf-8' );
        $str = $codec->convertString( $str ); // Make sure the string is in utf-8
        $out = explode( "/", $str ); // Don't encode the slashes
        foreach ( $out as $i => $o )
        {
            if ( preg_match( "#^[\(]([a-zA-Z0-9_]+)[\)]#", $o, $m ) )
            {
                // Don't encode '(' and ')' in user parameters
                $out[$i] = '(' . urlencode( $m[1] ) . ')';
            }
            else
            {
                $out[$i] = urlencode( $o ); // Let PHP do the rest
            }
        }
        $tmp = join( "/", $out );
        // Don't encode '~' in URLs
        $tmp = str_replace( '%7E', '~', $tmp );
        return $tmp;
    }
161508
public static function replaceSpecialChars($str)
    {
        return preg_replace(array_keys(self::$specialCharsArray), array_values(self::$specialCharsArray), $str);
    }
900437
public function search_slugify($str = '')
    {
        try {
            $options = [
                'separator' => '+'
            ];

            return $this->slugify($str, $options);
        }
        catch (\Exception $e) {
            if (function_exists('log_message')) {
                $message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
                log_message('error', $message);
            }

            return $this->common->convertStrToEn($str, '+');
        }
    }
900474
protected static function normalize($str)
    {
        $str = static::normalizeNewLines($str);
        // remove control characters; leave \t + \n
        $str = preg_replace('#[\x00-\x08\x0B-\x1F\x7F-\x9F]+#u', '', $str);
        // right trim
        $str = preg_replace('#[\t ]+$#m', '', $str);
        // leading and trailing blank lines
        $str = trim($str, "\n");

        return $str;
    }
1279230
public static function makeHTMLString($str)
    {

        $str = trim($str);
        $str = htmlspecialchars($str, ENT_COMPAT, 'utf-8');

        return nl2br($str);
    }
171126
public static function encode(String $str) : String
    {
        $chars = self::$numericalCodes;

        return str_replace(array_keys($chars), array_values($chars), $str);
    }