示例#1
0
 /**
  * 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);
 }
示例#2
0
 /**
  * Charset conversions can lead to situations, when a char can not be translated. This setting
  * controls how the behavior is in this situations. 
  * 
  * It can be either:
  * - CONVERSION_BEHAVIOR_EXCEPTION: An exception is thrown.
  * - CONVERSION_BEHAVIOR_REMOVE: The char is removed.
  * - CONVERSION_BEHAVIOR_REPLACE: The char is replaced by a best fit or removed when no replacement exists.
  * 
  * @param bit $behavior
  * @return void
  */
 public static function setConversionBehavior($behavior)
 {
     self::$conversionBehavior = $behavior;
 }