/** * This method replaces all special chars with HTML entities. * This * method does also consider entities which are not handled by * htmlentities. * * This method does not replace XML special chars (quotes etc.). * * @return Customweb_Core_String */ public function replaceNonAsciiCharsWithEntities() { $string = $this; $utf8Charset = Customweb_Core_Charset::forName('UTF-8'); if ($this->getCharset() != $utf8Charset) { $string = $this->convertTo('UTF-8'); } $charArray = $utf8Charset->toArray($string->string); $result = ''; for ($i = 0; $i < count($charArray); $i++) { $char = $charArray[$i]; $ord = Customweb_Core_Charset_UTF8::getUnicode($char); if ($ord > 127) { $result .= '&#' . $ord . ';'; } else { $result .= $char; } } return new Customweb_Core_String($result, $utf8Charset); }
/** * This method sets the default charset. The default charset is used, whenever * no charset is provided. * * Changing the default charset may have a high impact on the whole string * manipulation. Per default UTF-8 is set as the default charset. * * @param string | Customweb_Core_Charset $charset * @throws Exception * @return Customweb_Core_Charset */ public static function setDefaultCharset($charset) { if (is_string($charset)) { $charset = Customweb_Core_Charset::forName($charset); } else { if (!$charset instanceof Customweb_Core_Charset) { throw new Customweb_Core_Exception_CastException('Customweb_Core_Charset'); } } self::$defaultCharset = $charset; return self::$defaultCharset; }