Replace discouraged characters introduced by Microsoft Word

@param   string   $text        Text to clean
@param   boolean  $quotesOnly  Only clean quotes (single and double)
@return  string
488456
public static function cleanMsChar($text, $quotesOnly=false)
	{
		$y = array(
			"\x7f"=>'',
			"\x80"=>'&#8364;',
			"\x81"=>'',
			"\x83"=>'&#402;',
			"\x85"=>'&#8230;',
			"\x86"=>'&#8224;',
			"\x87"=>'&#8225;',
			"\x88"=>'&#710;',
			"\x89"=>'&#8240;',
			"\x8a"=>'&#352;',
			"\x8b"=>'&#8249;',
			"\x8c"=>'&#338;',
			"\x8d"=>'',
			"\x8e"=>'&#381;',
			"\x8f"=>'',
			"\x90"=>'',
			"\x95"=>'&#8226;',
			"\x96"=>'&#8211;',
			"\x97"=>'&#8212;',
			"\x98"=>'&#732;',
			"\x99"=>'&#8482;',
			"\x9a"=>'&#353;',
			"\x9b"=>'&#8250;',
			"\x9c"=>'&#339;',
			"\x9d"=>'',
			"\x9e"=>'&#382;',
			"\x9f"=>'&#376;',
		);
		$x = array(
			"\x82"=>'\'',
			"\x84"=>'"',
			"\x91"=>'\'',
			"\x92"=>'\'',
			"\x93"=>'"',
			"\x94"=>'"'
		);
		if (!$quotesOnly)
		{
			$x = $y + $x;
		}

		$text = strtr($text, $x);

		return $text;
	}
456319
private static function replace(string $text, Array $data = null): string {
    if (!empty($text) && count($data)) {
      if ($metaText = (new ReplaceText())->replace($text, $data)) {
        $text = $metaText;
      }
    }
    return $text;
  }
23613
public static function replaceOuterQuotes($text, $outerOpenQuote, $outerCloseQuote, $innerOpenQuote, $innerCloseQuote)
    {
        if (preg_match("/(.*)$outerOpenQuote(.+)$outerCloseQuote(.*)/u", $text, $match)) {
            return $match[1] . $innerOpenQuote . $match[2] . $innerCloseQuote . $match[3];
        }
        return $text;
    }
1313010
protected function sanitize_text( $text ) {
		// not fancy
		$text = strip_tags( $text );
		$text = esc_html( $text );
		$text = trim( $text );

		return $text;
	}
879110
public static function clearTextAllowedTags(string $text = null) : string
    {
        if (is_null($text)){
            return '';
        }
        return strip_tags(trim($text), '<p><a><strong><em><ul><li><ol><h1><h2><h3>');
    }
394765
private function replaceNamespace($text, $namespace, $escape = false)
    {
        // Clean Values:
        
        $default   = rtrim($this->getConfig('default-app-namespace'), '\\');
        $namespace = rtrim($namespace, '\\');
        
        // Handle Escaping:
        
        if ($escape) {
            $default   = addslashes($default);
            $namespace = addslashes($namespace);
        }
        
        // Replace Namespace:
        
        $text = str_replace($default, $namespace, $text);
        
        // Answer Text:
        
        return $text;
    }
956510
private function replaceWithDelimiter(string $text, string $valid, string $delimiter): string
	{
		$quoted = preg_quote($delimiter);

		// Replace all invalid characters with a single delimiter
		$text = preg_replace(
			'((?:[^'.$valid.']|'.$quoted.')+)us',
			$delimiter,
			$text
		);

		// Remove delimiters from the beginning and the end
		$text = preg_replace('(^(?:'.$quoted.')+|(?:'.$quoted.')+$)us', '', $text);

		return $text;
	}
990274
public static function escapeTrailingBackslash($text)
    {
        if ('\\' === substr($text, -1)) {
            $len = strlen($text);
            $text = rtrim($text, '\\');
            $text .= str_repeat('<<', $len - strlen($text));
        }

        return $text;
    }
272052
protected function _filterText($text)
    {
        // return true means `yes, it's banned`
        if (is_callable($this->config('bannedWords'))) {
            $isBanned = function ($word) {
                $callable = $this->config('bannedWords');

                return $callable($word);
            };
        } else {
            $isBanned = function ($word) {
                return in_array($word, (array)$this->config('bannedWords')) || empty($word);
            };
        }

        $words = explode(' ', $text);
        foreach ($words as $i => $w) {
            if ($isBanned($w)) {
                unset($words[$i]);
            }
        }

        return implode(' ', $words);
    }
1046669
public String replace(CharSequence text) {
        TextBuffer tb = wrap(new StringBuilder(text.length()));
        replace(pattern.matcher(text), substitution, tb);
        return tb.toString();
    }
781633
protected function __fixPersianString($text){
       
       if(is_null($text))
          return null;
       $replacePairs = array(
                chr(0xD9).chr(0xA0) => chr(0xDB).chr(0xB0),
                chr(0xD9).chr(0xA1) => chr(0xDB).chr(0xB1),
                chr(0xD9).chr(0xA2) => chr(0xDB).chr(0xB2),
                chr(0xD9).chr(0xA3) => chr(0xDB).chr(0xB3),
                chr(0xD9).chr(0xA4) => chr(0xDB).chr(0xB4),
                chr(0xD9).chr(0xA5) => chr(0xDB).chr(0xB5),
                chr(0xD9).chr(0xA6) => chr(0xDB).chr(0xB6),
                chr(0xD9).chr(0xA7) => chr(0xDB).chr(0xB7),
                chr(0xD9).chr(0xA8) => chr(0xDB).chr(0xB8),
                chr(0xD9).chr(0xA9) => chr(0xDB).chr(0xB9),
                chr(0xD9).chr(0x83) => chr(0xDA).chr(0xA9),
                chr(0xD9).chr(0x89) => chr(0xDB).chr(0x8C),
                chr(0xD9).chr(0x8A) => chr(0xDB).chr(0x8C),
                chr(0xDB).chr(0x80) => chr(0xD9).chr(0x87) . chr(0xD9).chr(0x94));
       return strtr($text, $replacePairs);
   }
846979
final public function getEscaped($text, $extra = false)
    {
        $result = mysqli_real_escape_string($this->resourceId, $text);
        if ($extra) {
            $result = addcslashes($result, '%_');
        }
        return $result;
    }
75354
public static function format($text) {
		$text = preg_replace_callback('/<b>(.+?)<\/b>/', function($matches) {
			return SS_Cli::text($matches[1], null, null, true);
		}, $text);

		$text = preg_replace_callback('/<success>(.+?)<\/success>/', function($matches) {
			return SS_Cli::text($matches[1], 'green', null, true);
		}, $text);

		$text = preg_replace_callback('/<error>(.+?)<\/error>/', function($matches) {
			return SS_Cli::text($matches[1], 'red', null, true);
		}, $text);

		$text = preg_replace_callback('/<caution>(.+?)<\/caution>/', function($matches) {
			return SS_Cli::text($matches[1], 'yellow', null, true);
		}, $text);

		$text = preg_replace_callback('/<info>(.+?)<\/info>/', function($matches) {
			return SS_Cli::text($matches[1], 'cyan', null, true);
		}, $text);


		return $text;
	}
763655
private function formatAsTitle($text)
    {
        $titleLines = array();

        $titleLines[] = str_repeat('#', $this->maxLineLength);
        $titleLines[] = rtrim($this->formatAsSubtitle($text), PHP_EOL);
        $titleLines[] = str_repeat('#', $this->maxLineLength);

        return implode(PHP_EOL, $titleLines).PHP_EOL;
    }
717050
public function replaceMacros($text)
    {
        $result = str_replace(
            array(
                '$(httpHost)',
                '$(httpPath)',
                '$(httpRoot)',
                '$(styleRoot)',
                '$(dataRoot)',

                '$(siteName)',
                '$(siteTitle)',
                '$(siteKeywords)',
                '$(siteDescription)',
            ),
            array(
                httpHost,
                httpPath,
                Eresus_CMS::getLegacyKernel()->root,
                styleRoot,
                dataRoot,

                siteName,
                siteTitle,
                siteKeywords,
                siteDescription,
            ),
            $text
        );
        $result = preg_replace_callback('/\$\(const:(.*?)\)/i', '__macroConst', $result);
        $result = preg_replace_callback('/\$\(var:(([\w]*)(\[.*?\]){0,1})\)/i', '__macroVar', $result);
        $result = preg_replace('/\$\(\w+(:.*?)*?\)/', '', $result);
        return $result;
    }
1191300
public function quote($text)
    {
        if ($con = $this->getConnection()) {
            return $con->quote($text);
        } else {
            return "'" . $this->disconnectedEscapeText($text) . "'";
        }
    }
1289491
public static function cleanText(string $text)
    {
        $text = preg_replace('/<script[^>]*>.*?</script>/si', '', $text);
        $text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text);
        $text = preg_replace('/<!--.+?-->/', '', $text);
        $text = preg_replace('/{.+?}/', '', $text);
        $text = preg_replace('/&nbsp;/', ' ', $text);
        $text = preg_replace('/&amp;/', ' ', $text);
        $text = preg_replace('/&quot;/', ' ', $text);
        $text = strip_tags($text);
        $text = htmlspecialchars($text);

        return $text;
    }