Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
 public function testUtf8Query()
 {
     $sql = "INSERT INTO " . $this->tableName . "\n      SET\n        page_template = '" . $this->db->escape(UTF8::urldecode('D%26%23xFC%3Bsseldorf')) . "',\n        page_type = '" . UTF8::urldecode('Düsseldorf') . "'\n    ";
     $return = $this->db->execSQL($sql);
     self::assertEquals(true, is_int($return));
     self::assertEquals(true, $return > 0);
     $data = $this->db->select($this->tableName, 'page_id=' . (int) $return);
     $dataArray = $data->fetchArray();
     self::assertEquals('Düsseldorf', $dataArray['page_template']);
     self::assertEquals('Düsseldorf', $dataArray['page_type']);
 }