Esempio n. 1
0
File: utf8.php Progetto: rair/yacs
 /**
  * transcode to ISO 8859
  *
  * To be used only when there is no other alternative.
  *
  * @link http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-15.TXT ISO/IEC 8859-15:1999 to Unicode
  *
  * @param string a complex string using unicode entities
  * @param string optional characters to accept
  * @return a ISO 8859 string
  *
  * @see feeds/flash/slashdot.php
  */
 public static function &to_iso8859($utf, $options = '')
 {
     // iso-8859-15 + Microsoft extensions cp1252
     list($iso_entities, $unicode_entities) = Utf8::get_iso8859();
     // transcode Unicode entities to iso 8859
     $text = str_replace($unicode_entities, $iso_entities, $utf);
     // translate only 1-byte entities
     $areas = preg_split('/&#(\\d+);/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
     $text = '';
     $index = 0;
     foreach ($areas as $area) {
         switch ($index % 2) {
             case 0:
                 // before entity
                 $text .= $area;
                 break;
             case 1:
                 // the entity itself
                 // get the integer value
                 $unicode = intval($area);
                 // one ASCII byte
                 if ($unicode < 0xff) {
                     $text .= chr($unicode);
                 } else {
                     $text .= '_';
                 }
                 break;
         }
         $index++;
     }
     // done
     return $text;
 }