Replace special characters in a given string

@access public
@param string $str The string in which to replace special characters
@return string The string with the special characters replaced
161508
public static function replaceSpecialChars($str)
    {
        return preg_replace(array_keys(self::$specialCharsArray), array_values(self::$specialCharsArray), $str);
    }
1218463
public function unescapeMd($str)
    {
        if (strpos ($str,'\\') === false) return $str;
        return preg_replace(self::UNESCAPE_MD_RE, '$1', $str);
    }
1110372
public static function toAscii(string $str) : string
    {
        $clean = preg_replace('/[^a-zA-Z0-9\.\/_|+ -]/', '', $str);
        $clean = strtolower(trim($clean, '-'));
        $clean = preg_replace('/[\/_|+ -]+/', '-', $clean);

        return $clean;
    }
82265
private function _strtoupper($str)
    {
        $str = html_entity_decode($str, ENT_COMPAT);

        if (function_exists('mb_strtoupper')) {
            $str = mb_strtoupper($str, 'UTF-8');
        } else {
            $str = strtoupper($str);
        }

        $str = htmlspecialchars($str, ENT_COMPAT);

        return $str;
    }
20572
private function escapeValue(&$str): string
    {
        $search = [
            $this->symbRel,
            $this->sepComp,
            $this->sepData,
            $this->symbEnd,
        ];
        $replace = [
            $this->symbRel . $this->symbRel,
            $this->symbRel . $this->sepComp,
            $this->symbRel . $this->sepData,
            $this->symbRel . $this->symbEnd,
        ];

        return \str_replace($search, $replace, $str);
    }
1187879
public function cleanString($str)
	{
		$str = preg_replace("/[áàâãªä]/u", "a", $str);
		$str = preg_replace("/[ÁÀÂÃÄ]/u", "A", $str);
		$str = preg_replace("/[ÍÌÎÏ]/u", "I", $str);
		$str = preg_replace("/[íìîï]/u", "i", $str);
		$str = preg_replace("/[éèêë]/u", "e", $str);
		$str = preg_replace("/[ÉÈÊË]/u", "E", $str);
		$str = preg_replace("/[óòôõºö]/u", "o", $str);
		$str = preg_replace("/[ÓÒÔÕÖ]/u", "O", $str);
		$str = preg_replace("/[úùûü]/u", "u", $str);
		$str = preg_replace("/[ÚÙÛÜ]/u", "U", $str);
		$str = preg_replace("/[’‘‹›‚]/u", "'", $str);
		$str = preg_replace("/[“”«»„]/u", '"', $str);
		$str = str_replace("–", "-", $str);
		$str = str_replace(" ", " ", $str);
		$str = str_replace("ç", "c", $str);
		$str = str_replace("Ç", "C", $str);
		$str = str_replace("ñ", "n", $str);
		$str = str_replace("Ñ", "N", $str);
		
		$trans = get_html_translation_table(HTML_ENTITIES);
		$trans[chr(130)] = '&sbquo;';    // Single Low-9 Quotation Mark
		$trans[chr(131)] = '&fnof;';    // Latin Small Letter F With Hook
		$trans[chr(132)] = '&bdquo;';    // Double Low-9 Quotation Mark
		$trans[chr(133)] = '&hellip;';    // Horizontal Ellipsis
		$trans[chr(134)] = '&dagger;';    // Dagger
		$trans[chr(135)] = '&Dagger;';    // Double Dagger
		$trans[chr(136)] = '&circ;';    // Modifier Letter Circumflex Accent
		$trans[chr(137)] = '&permil;';    // Per Mille Sign
		$trans[chr(138)] = '&Scaron;';    // Latin Capital Letter S With Caron
		$trans[chr(139)] = '&lsaquo;';    // Single Left-Pointing Angle Quotation Mark
		$trans[chr(140)] = '&OElig;';    // Latin Capital Ligature OE
		$trans[chr(145)] = '&lsquo;';    // Left Single Quotation Mark
		$trans[chr(146)] = '&rsquo;';    // Right Single Quotation Mark
		$trans[chr(147)] = '&ldquo;';    // Left Double Quotation Mark
		$trans[chr(148)] = '&rdquo;';    // Right Double Quotation Mark
		$trans[chr(149)] = '&bull;';    // Bullet
		$trans[chr(150)] = '&ndash;';    // En Dash
		$trans[chr(151)] = '&mdash;';    // Em Dash
		$trans[chr(152)] = '&tilde;';    // Small Tilde
		$trans[chr(153)] = '&trade;';    // Trade Mark Sign
		$trans[chr(154)] = '&scaron;';    // Latin Small Letter S With Caron
		$trans[chr(155)] = '&rsaquo;';    // Single Right-Pointing Angle Quotation Mark
		$trans[chr(156)] = '&oelig;';    // Latin Small Ligature OE
		$trans[chr(159)] = '&Yuml;';    // Latin Capital Letter Y With Diaeresis
		$trans['euro'] = '&euro;';    // euro currency symbol
		ksort($trans);
		 
		foreach ($trans as $k => $v) {
			$str = str_replace($v, $k, $str);
		}
		
		$str = strip_tags($str);
		$str = html_entity_decode($str);
		$str = preg_replace('/[^(\x20-\x7F)]*/','', $str);
		$targets=array('\r\n', '\n', '\r', '\t');
		$results=array(" ", " ", " ", "");
		$str = str_replace($targets, $results, $str);
		
		return ($str);
	}
199318
public static function encode(String $str) : String
    {
        return str_replace(array_keys(self::$phpTagChars), array_values(self::$phpTagChars), $str);
    }
288744
protected static function convertToLowercase($str)
    {
        $explodedStr = explode('_', $str);

        if (count($explodedStr) > 1) {
            $lowerCasedStr = [];
            foreach ($explodedStr as $value) {
                $lowerCasedStr[] = strtolower($value);
            }
            $str = implode('_', $lowerCasedStr);
        }

        return $str;
    }
466060
public static function formataFone($str)
    {
        $str = preg_replace("/[^0-9]/", '', $str);
        if (!$str) {
            return '';
        }
        if ('0800' == substr($str, 0, 4)) {
            $srt = substr($str, -11, -7) . ' ' . substr($str, -7, -4) . '-' . substr($str, -4);
        } elseif (11 == strlen($str)) {
            $srt = '(' . substr($str, -11, -9) . ') ' . substr($str, -9, -4) . '-' . substr($str, -4);
        } else {
            $srt = '(' . substr($str, -10, -8) . ') ' . substr($str, -8, -4) . '-' . substr($str, -4);
        }

        return $srt;
    }
1041691
public static function convertQuotes($str)
    {

        $r = "/\[q(?:uote)?\](.*?)\[\/q(?:uote)?\]/is";
        while(preg_match($r, $str)){
            $str = preg_replace($r, '<blockquote class="quote"><p>\\1</p></blockquote>', $str);
        }

        return $str;
    }
741815
function clean_string($str)
	{
		if ($this->_is_ascii($str) === FALSE)
		{
			$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
		}

		return $str;
	}
994282
private static function utf8_to_unicode( &$str )
    {
        $unicode = array();
        $values = array();
        $looking_for = 1;

        for ($i = 0; $i < strlen( $str ); $i++ ) {
            $this_value = ord( $str[ $i ] );
            if ( $this_value < 128 ) $unicode[] = $this_value;
            else {
                if ( count( $values ) == 0 ) $looking_for = ( $this_value < 224 ) ? 2 : 3;
                $values[] = $this_value;
                if ( count( $values ) == $looking_for ) {
                    $number = ( $looking_for == 3 ) ?
                        ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
                        ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
                    $unicode[] = $number;
                    $values = array();
                    $looking_for = 1;
                }
            }
        }
        return $unicode;
    }
481757
public static function replaceRomanArray(array $str) : array
    {
        foreach ($str as $key => $value) {
            $code = Mbstring::mb_ord($value);
            if ($code >= 8544 && $code <= 8555) {
                $str[$key] = self::toRoman($code - 8543);
            } elseif ($code >= 8560 && $code <= 8571) {
                $str[$key] = self::toSmallRoman($code - 8559);
            } else {
                switch ($code) {
                    case 8556:
                        $str[$key] = self::toRoman(50);
                        break;
                    case 8557:
                        $str[$key] = self::toRoman(100);
                        break;
                    case 8558:
                        $str[$key] = self::toRoman(500);
                        break;
                    case 8559:
                        $str[$key] = self::toRoman(1000);
                        break;
                    case 8572:
                        $str[$key] = self::toSmallRoman(50);
                        break;
                    case 8573:
                        $str[$key] = self::toSmallRoman(100);
                        break;
                    case 8574:
                        $str[$key] = self::toSmallRoman(500);
                        break;
                    case 8575:
                        $str[$key] = self::toSmallRoman(1000);
                        break;
                    default:
                        break;
                }
            }
        }
        return $str;
    }
468973
public function replace($str)
    {
        // search for patterns like links and e-mail addresses
        $str = preg_replace_callback($this->link_pattern, array($this, 'link_callback'), $str);
        $str = preg_replace_callback($this->mailto_pattern, array($this, 'mailto_callback'), $str);
        // resolve link references
        $str = preg_replace_callback($this->linkref_index, array($this, 'linkref_addindex'), $str);
        $str = preg_replace_callback($this->linkref_pattern, array($this, 'linkref_callback'), $str);

        return $str;
    }
487684
public function decode($str)
	{
		if ($this->decodeHtmlEntities && strpos($str, '&') !== false)
		{
			$str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
		}
		$str = str_replace("\x1A", '', $str);

		if ($this->hasEscapedChars)
		{
			$str = strtr(
				$str,
				[
					"\x1B0" => '!', "\x1B1" => '"', "\x1B2" => "'", "\x1B3" => '(',
					"\x1B4" => ')', "\x1B5" => '*', "\x1B6" => '[', "\x1B7" => '\\',
					"\x1B8" => ']', "\x1B9" => '^', "\x1BA" => '_', "\x1BB" => '`',
					"\x1BC" => '~'
				]
			);
		}

		return $str;
	}
1351774
public static function decorateTT($str)
    {
        $str = htmlspecialchars($str, ENT_QUOTES);
        $str = preg_replace('/`([^`]*)`/', '<tt>\\1</tt>', $str);

        return $str;
    }
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;
  }