Beispiel #1
0
 /**
  * Transliterates characters to their ASCII equivalents.
  * $language specifies a priority for a specific language.
  * The latter is useful if languages have different rules for the same character.
  *
  * @param String $text
  * @param String $language
  * @param boolean $asciiOnlyForLanguage set to "true" if you only want to convert the language-maps
  *
  * @param string $substChr
  *
  * @return string
  */
 public static function downcode($text, $language = 'de', $asciiOnlyForLanguage = false, $substChr = '')
 {
     self::init($language);
     $text = UTF8::urldecode($text);
     $searchArray = array();
     $replaceArray = array();
     if (preg_match_all(self::$regex, $text, $matches)) {
         $matchesCounter = count($matches[0]);
         for ($i = 0; $i < $matchesCounter; $i++) {
             $char = $matches[0][$i];
             if (isset(self::$map[$char])) {
                 $searchArray[] = $char;
                 $replaceArray[] = self::$map[$char];
             }
         }
     }
     $text = str_replace($searchArray, $replaceArray, $text);
     // convert everything into ASCII
     if ($asciiOnlyForLanguage === true) {
         return (string) $text;
     } else {
         return UTF8::to_ascii($text, $substChr);
     }
 }
Beispiel #2
0
 /**
  * Returns an ASCII version of the string. A set of non-ASCII characters are
  * replaced with their closest ASCII counterparts, and the rest are removed
  * unless instructed otherwise.
  *
  * @param $strict [optional] <p>Use "transliterator_transliterate()" from PHP-Intl | WARNING: bad performance</p>
  *
  * @return Stringy Object whose $str contains only ASCII characters
  */
 public function toAscii($strict = false)
 {
     $str = UTF8::to_ascii($this->str, '?', $strict);
     return static::create($str, $this->encoding);
 }