Generate slug.

@param string $string Input string.
@param string $replacement Replacement string.
@return string Sluggified string.
779482
public function slug($string, $replacement = '-')
    {
        $options = $this->config;
        $regex = $options['regex'];
        unset($options['regex']);

        return Slugify::create($regex, $options)->slugify($string, $replacement);
    }
953542
public function slugify($string)
    {
        $decoder = $this->getUniDecoder();

        if (null !== $decoder) {
            $string = $decoder->decode($string);
        }

        $string = strtolower($string);
        $string = str_replace("'", '', $string);
        $string = preg_replace('([^a-zA-Z0-9_-]+)', '-', $string);
        $string = preg_replace('(-{2,})', '-', $string);
        $string = trim($string, '-');

        return $string;
    }
1075713
public static function slug(string $string, string $separator = '.'): string
    {
        // Make sure standard characters has been replaced to separator.
        $slug = str_replace(['-', '_', ' ', '.'], $separator, mb_strtolower($string));

        // Remove all "funny" characters.
        $slug = preg_replace('/[^a-z0-9' . preg_quote($separator) . ']/', '', $slug);

        return $slug;
    }
1001714
public static function slugify($str, $replace = array(), $delimiter = '-')
    {
        if (!empty($replace)) {
            $str = str_replace((array)$replace, ' ', $str);
        }

        $clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
        $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
        $clean = strtolower(trim($clean, '-'));
        $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);

        return $clean;
    }
253389
public function slugify($string, $replacement = '-')
    {
        // special replacement map
        $slug = strtr($string, array(
            'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
            'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
            'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
            'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
            'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y'
        ));

        return trim(  // clear extra replacement chars
            preg_replace( // replace "non letter" and "digits"
                '/\W+/',
                $replacement,
                strtolower($slug)
            ),
            $replacement
        );
    }
198864
public static function alias($string)
    {
        $cleaned = self::strip($string);
        $cleaned = Str::slug($cleaned);

        return $cleaned;
    }
919572
public function stringReplace($string, $replace)
    {
        if ($this->_mappingsChanged) {
            $this->_generateMappings();
        }

        if (strpos("\n", $string)) {
            throw new Exception('string must not contain \n');
        }
        if ($replace != "" && strpos("\n", $replace)) {
            throw new Exception('replace must not contain \n');
        }

        $adjustOffsets = array();
        $pos = 0;
        $str = $this->_fileContents;
        $offset = 0;
        $lineOffset = 0;
        while (($pos = strpos($str, $string, $pos)) !== false) {
            $line = substr_count(substr($str, 0, $pos), "\n") + 1;
            if (!isset($adjustOffsets[$line])) {
                //first in line
                $lineOffset = 0;
            }
            $this->_fileContents = substr($this->_fileContents, 0, $pos + $offset).$replace.substr($this->_fileContents, $pos + $offset + strlen($string));
            $offset += strlen($replace) - strlen($string);
            $lineOffset += strlen($replace) - strlen($string);
            $column = $pos - strrpos(substr($str, 0, $pos), "\n") + 1; //strrpos can return false for first line which will subtract 0 (=false)
            $adjustOffsets[$line][] = array(
                'column' => $column,
                'absoluteOffset' => $offset,
                'lineOffset' => $lineOffset,
                'offset' => strlen($replace) - strlen($string),
                'replacedLength' => strlen($string)
            );
            $pos = $pos + strlen($string);
        }

        $mappings = $this->getMappings();
        $this->_mappingsChanged = true;
        $this->_mappings = array();
        foreach ($mappings as $mappingIndex=>$mapping) {
            if (isset($adjustOffsets[$mapping['generatedLine']])) {
                foreach (array_reverse($adjustOffsets[$mapping['generatedLine']], true) as $offsIndex=>$offs) {
                    if ($mapping['generatedColumn'] > $offs['column']) {
                        if ($mapping['generatedColumn'] < $offs['column']-1+$offs['replacedLength']) {
                            //mapping inside replaced test, remove
                            continue 2;
                        } else {
                            $mapping['generatedColumn'] += $offs['lineOffset'];
                            break;
                        }
                    }
                }
            }
            $this->_mappings[] = $mapping;
        }
    }
611254
public static function slug(string $string): string
    {
        if ($string == '') {
            return '';
        }

        $s = strip_tags(trim($string));

        $table = [
          'Š' => 'S',
          'š' => 's',
          'Đ' => 'Dj',
          'đ' => 'dj',
          'Ž' => 'Z',
          'ž' => 'z',
          'Č' => 'C',
          'č' => 'c',
          'Ć' => 'C',
          'ć' => 'c',
          'À' => 'A',
          'Á' => 'A',
          'Â' => 'A',
          'Ã' => 'A',
          'Ä' => 'A',
          'Å' => 'A',
          'Æ' => 'A',
          'Ç' => 'C',
          'È' => 'E',
          'É' => 'E',
          'Ê' => 'E',
          'Ë' => 'E',
          'Ì' => 'I',
          'Í' => 'I',
          'Î' => 'I',
          'Ï' => 'I',
          'Ñ' => 'N',
          'Ò' => 'O',
          'Ó' => 'O',
          'Ô' => 'O',
          'Õ' => 'O',
          'Ö' => 'O',
          'Ø' => 'O',
          'Ù' => 'U',
          'Ú' => 'U',
          'Û' => 'U',
          'Ü' => 'U',
          'Ý' => 'Y',
          'Þ' => 'B',
          'ß' => 'Ss',
          'à' => 'a',
          'á' => 'a',
          'â' => 'a',
          'ã' => 'a',
          'ä' => 'a',
          'å' => 'a',
          'æ' => 'a',
          'ç' => 'c',
          'è' => 'e',
          'é' => 'e',
          'ê' => 'e',
          'ë' => 'e',
          'ì' => 'i',
          'í' => 'i',
          'î' => 'i',
          'ï' => 'i',
          'ð' => 'o',
          'ñ' => 'n',
          'ò' => 'o',
          'ó' => 'o',
          'ô' => 'o',
          'õ' => 'o',
          'ö' => 'o',
          'ø' => 'o',
          'ù' => 'u',
          'ú' => 'u',
          'û' => 'u',
          'ý' => 'y',
          'þ' => 'b',
          'ÿ' => 'y',
          'Ŕ' => 'R',
          'ŕ' => 'r',
        ];

        $s = strtr($s, $table);

        $rpl = [
          '/(,|;|\!|\?|:|&|\+|\=|-|\'|\/|\*|\t|\n|\%|#|\^|\(|\)|\[|\]|\{|\}|\.)/' => '-',

          '/≈°/' => 's',
          '/ƒë/' => 'd',
          '/ƒç/' => 'c',
          '/ƒá/' => 'c',
          '/≈æ/' => 'z',
          '/≈†/' => 's',
          '/ƒê/' => 'd',
          '/ƒå/' => 'c',
          '/ƒÜ/' => 'c',
          '/≈Ω/' => 'z',

          '/&353;/' => 's',
          '/&273;/' => 'd',
          '/&269;/' => 'c',
          '/&263;/' => 'c',
          '/&382;/' => 'z',
          '/&351;/' => 'S',
          '/&272;/' => 'D',
          '/&268;/' => 'C',
          '/&262;/' => 'C',
          '/&381;/' => 'Z'
        ];

        $s = preg_replace(array_keys($rpl), array_values($rpl), $s);

        $s = str_replace('\\', '', $s);
        $s = str_replace('¬Æ', '-', $s);
        $s = str_replace('‚Äì', '-', $s);
        $s = str_replace('¬©', '-', $s);
        $s = str_replace('√ü', '', $s);
        $s = str_replace('’', '', $s);

        $s = str_replace('€', 'eur', $s);
        $s = str_replace('$', 'usd', $s);
        $s = str_replace('£', 'pound', $s);
        $s = str_replace('¥', 'yen', $s);

        $s = str_replace(' ', '-', $s);

        while (strpos($s, '--') !== false) {
            $s = str_replace('--', '-', $s);
        }

        $s = preg_replace('~[^\\pL\d]+~u', '-', $s);
        $s = trim($s, '-');
        $s = iconv('utf-8', 'us-ascii//TRANSLIT', $s);
        $s = strtolower($s);
        $s = preg_replace('~[^-\w]+~', '', $s);

        return $s;
    }
959065
protected function replace($string)
    {
        foreach ($this->patterns as $key => $value) {
            $string = str_replace($key, $value, $string);
        }

        return $string;
    }
1357331
public function slugFilter($string, $convertCase = true, $separator = '-')
    {
        return StringHelper::slug($string, $convertCase, $separator);
    }
1043970
public function urlize(string $string) : string
    {
        // Remove all non url friendly characters with the unaccent function
        $unaccented = $this->unaccent($string);

        if (function_exists('mb_strtolower')) {
            $lowered = mb_strtolower($unaccented);
        } else {
            $lowered = strtolower($unaccented);
        }

        $replacements = [
            '/\W/' => ' ',
            '/([A-Z]+)([A-Z][a-z])/' => '\1_\2',
            '/([a-z\d])([A-Z])/' => '\1_\2',
            '/[^A-Z^a-z^0-9^\/]+/' => '-',
        ];

        $urlized = $lowered;

        foreach ($replacements as $pattern => $replacement) {
            $replaced = preg_replace($pattern, $replacement, $urlized);

            if ($replaced === null) {
                throw new RuntimeException(sprintf(
                    'preg_replace returned null for value "%s"',
                    $urlized
                ));
            }

            $urlized = $replaced;
        }

        return trim($urlized, '-');
    }
670090
public function replace($string)
    {
        foreach ($this->bag as $key => $value) {
            $string = str_replace($key, $value, $string);
        }

        return $string;
    }
1267025
static function censor($str, array $censored, $replacement = '') {
        foreach ($censored as $bad) {
            $str = preg_replace("/$bad/i", $replacement, $str);
        }

        return $str;
    }
401143
public static function last_replace($search, $replace, $string)
    {
        $pos = strrpos($string, $search);
        
        if($pos !== false)
        {
            return substr_replace($string, $replace, $pos, strlen($search));
        }
        else
        {
            return $string;
        }
    }
447343
public static function createSlug($string)
	{
		// remove all accent characters
		$string = self::remove_accents($string);

		// lowercase
		$string = strtolower($string);

		// replace all characters except letters and numbers to dashes
		$slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $string);

		// deep replace double dashes
		while(strpos('--', $slug))
		{
			$slug = str_replace('--', '-', $slug);
		}

		// trim dashes at start and end
		$slug = trim($slug, '-');

		return $slug;
	}
1307901
public static function txt2Slug(?string $string): string
  {
    if ($string===null) return '';

    return trim(preg_replace('/[^0-9a-z]+/', '-', strtr(mb_strtolower($string), self::$trans)), '-');
  }
428203
protected function _directReplacements($string)
    {
        foreach ($this->DIRECT_NUMS as $dn => $dn_replacement) {
            $string = preg_replace("/$dn/i", $dn_replacement, $string);
        }
        return $string;
    }