Пример #1
0
 /**
  * Converts special characters to numeric htmlentities.
  *
  * <b>Note</b>:<br>
  * If supplied string is encoded with UTF-8, o umlaut ("�") will become two HTML entities instead of one.
  *
  * @param  string  $str  String to be converted.
  * @return string  String converted to numeric HTML entities.
  */
 public static function num_htmlentities($str)
 {
     if (!self::$htmlentities) {
         self::$htmlentities = array();
         foreach (get_html_translation_table(HTML_ENTITIES, ENT_QUOTES) as $char => $entity) {
             self::$htmlentities[$entity] = '&#' . ord($char) . ';';
         }
     }
     return str_replace(array_keys(self::$htmlentities), self::$htmlentities, htmlentities($str));
 }
Пример #2
0
 /**
  * Converts special characters to numeric htmlentities.
  *
  * <b>Note</b>:<br>
  * If supplied string is encoded with UTF-8, o umlaut ("ö") will become two
  * HTML entities instead of one.
  *
  * @param string $str String to be converted.
  *
  * @return string String converted to numeric HTML entities.
  */
 public static function num_htmlentities($str)
 {
     $charset = 'ISO-8859-1';
     if (!self::$htmlentities) {
         self::$htmlentities = array();
         $table = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, $charset);
         foreach ($table as $char => $entity) {
             self::$htmlentities[$entity] = '&#' . ord($char) . ';';
         }
     }
     return str_replace(array_keys(self::$htmlentities), self::$htmlentities, htmlentities($str, ENT_COMPAT | ENT_HTML401, $charset));
 }