note 89992 modified in function.mb-decode-numericentity by danbrown

From: Date: Wed, 01 Apr 2009 13:23:07 +0000
Subject: note 89992 modified in function.mb-decode-numericentity by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-152703@lists.php.net to get a copy of this message
Manual entity => utf8 conversion: <?php // parse entities $raw = preg_replace_callback ( "/&#(\\d+);/u", "_pcreEntityToUtf", $raw ); function _pcreEntityToUtf($matches) { $char = intval(is_array($matches) ? $matches[1] : $matches); if ($char < 0x80) { // to prevent insertion of control characters if ($char >= 0x20) return htmlspecialchars(chr($char)); else return "&#$char;"; } else if ($char < 0x8000) { return chr(0xc0 | (0x1f & ($char >> 6))) . chr(0x80 | (0x3f & $char)); } else { return chr(0xe0 | (0x0f & ($char >> 12))) . chr(0x80 | (0x3f & ($char >> 6))). chr(0x80 | (0x3f & $char)); } } ?> --was-- Manual entity => utf8 conversion: <?php // parse entities $raw = preg_replace_callback ( "/&#(\\d+);/u", "_pcreEntityToUtf", $raw ); function _pcreEntityToUtf($matches) { $char = intval(is_array($matches) ? $matches[1] : $matches); if ($char < 0x80) { // to prevent insertion of control characters if ($char >= 0x20) return htmlspecialchars(chr($char)); else return "&#$char;"; } else if ($char < 0x8000) { return chr(0xc0 | (0x1f & ($char >> 6))) . chr(0x80 | (0x3f & $char)); } else { return chr(0xe0 | (0x0f & ($char >> 12))) . chr(0x80 | (0x3f & ($char >> 6))). chr(0x80 | (0x3f & $char)); } } http://php.net/manual/en/function.mb-decode-numericentity.php

« previous php.notes (#152703) next »