本文整理汇总了PHP中mb_encode_numericentity函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_encode_numericentity函数的具体用法?PHP mb_encode_numericentity怎么用?PHP mb_encode_numericentity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mb_encode_numericentity函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: encodeEntities
public static function encodeEntities($str, $encoding = 'UTF-8', $convmap = null)
{
if ($convmap && function_exists('mb_encode_numericentity')) {
return mb_encode_numericentity($str, $convmap, $encoding);
}
return htmlentities($str, ENT_QUOTES, $encoding);
}
示例2: escape
public static function escape($string, $encoding = null)
{
if (empty($string)) {
return $string;
}
if (Kint::$enabled_mode === Kint::MODE_CLI) {
return str_replace("", '\\x1b', $string);
}
if (Kint::$enabled_mode === Kint::MODE_WHITESPACE) {
return $string;
}
if ($encoding === null) {
$encoding = self::detectEncoding($string);
}
$string = htmlspecialchars($string, ENT_NOQUOTES, $encoding === 'ASCII' ? 'UTF-8' : $encoding);
if ($encoding === 'UTF-8') {
// TODO: we could make the symbols hover-title show the code for the invisible symbol
// when possible force invisible characters to have some sort of display (experimental)
$string = preg_replace('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x80-\\x9F]/u', '?', $string);
}
// this call converts all non-ASCII characters into html chars of format
if (function_exists('mb_encode_numericentity')) {
$string = mb_encode_numericentity($string, array(0x80, 0xffff, 0, 0xffff), $encoding);
}
return $string;
}
示例3: courierimage
function courierimage($char, $width = 8, $height = 12, $pdir = 'patterns/')
{
$im = imagecreate($width, $height);
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
$imchar = $char;
$imchar = mb_encode_numericentity($imchar, array(0x0, 0xffff, 0, 0xffff), 'UTF-8');
// echo $imchar;
imagettftext($im, 10, 0, 0, 10, $text_color, 'cour.ttf', $imchar);
$imgarray_0 = img2array($im, $width, $height);
$imgarray_1 = img_array_split($imgarray_0);
$imgarray_2 = img_array_split($imgarray_1);
$ia2name = img_array_name($imgarray_2);
if (!file_exists($pdir . $ia2name)) {
mkdir($pdir . $ia2name);
}
$ia1name = img_array_name($imgarray_1);
if (!file_exists($pdir . $ia2name . '/' . $ia1name)) {
mkdir($pdir . $ia2name . '/' . $ia1name);
}
$ia0name = img_array_name($imgarray_0);
$filename = $pdir . $ia2name . '/' . $ia1name . '/' . $ia0name . '.txt';
if (!file_exists($filename)) {
writeUTF8File($filename, $char);
}
$filename = $pdir . $ia2name . '/' . $ia1name . '/' . $ia0name . '.gif';
if (!file_exists($filename)) {
ImageGif($im, $filename);
chmod($filename, 0777);
}
// echo '<table><tr><td>'.print_img_array($imgarray_0).'</td><td>'.print_img_array($imgarray_1).'</td><td>'.print_img_array($imgarray_2)."</td><td><img src=\"$filename\" /></td></table>";
}
示例4: kfJsonEncode
/**
* Polyfill for json_encode JSON_UNESCAPED_UNICODE (new in PHP 5.4.0) for PHP 5.3
*/
function kfJsonEncode($arr)
{
array_walk_recursive($arr, function (&$item, $key) {
if (is_string($item)) {
$item = mb_encode_numericentity($item, array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
}
});
return mb_decode_numericentity(json_encode($arr), array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
}
示例5: _convertUtf8ToSjis
/**
* Convert character encoding from UTF-8 to Shift_JIS.
*
* @param string $text
* @return string
*/
function _convertUtf8ToSjis($text)
{
$text = mb_encode_numericentity($text, $this->_utf8map, 'UTF-8');
$text = mb_convert_encoding($text, 'SJIS-win', 'UTF-8');
$pattern = '/&#(6\\d{4});/';
$callback = array($this, '_convertDecimalToSjis');
$text = preg_replace_callback($pattern, $callback, $text);
return $text;
}
示例6: escapeXML
public static function escapeXML($string)
{
$string = preg_replace('/&/is', '&', $string);
$string = preg_replace('/</is', '<', $string);
$string = preg_replace('/>/is', '>', $string);
$string = preg_replace('/\'/is', ''', $string);
$string = preg_replace('/"/is', '"', $string);
$string = str_replace(array('ą', 'ć', 'ę', 'ł', 'ń', 'ó', 'ś', 'ź', 'ż', 'Ą', 'Ć', 'Ę', 'Ł', 'Ń', 'Ó', 'Ś', 'Ź', 'Ż', 'ü', 'ò', 'è', 'à', 'ì'), array('a', 'c', 'e', 'l', 'n', 'o', 's', 'z', 'z', 'A', 'C', 'E', 'L', 'N', 'O', 'S', 'Z', 'Z', 'u', 'o', 'e', 'a', 'i'), $string);
return mb_encode_numericentity(trim($string), array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
}
示例7: json_encode_readable
function json_encode_readable($arr)
{
//convmap since 0x80 char codes so it takes all multibyte codes (above ASCII 127). So such characters are being "hidden" from normal json_encoding
array_walk_recursive($arr, function (&$item, $key) {
if (is_string($item)) {
$item = mb_encode_numericentity($item, array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
}
});
return mb_decode_numericentity(json_encode($arr), array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
}
示例8: _convertUtf8ToEntity
/**
* Callback function called by the filter() method.
*
* This function converts UTF-8 emoji to hexadecimal character reference.
*
* @param array $matches
* @return string
*/
function _convertUtf8ToEntity($matches)
{
$utf8 = $matches[0];
$entity = mb_encode_numericentity($utf8, $this->_convmap, 'UTF-8');
if ($utf8 !== $entity) {
$unicode = (int) substr($entity, 2, 5);
return '&#x' . dechex($unicode) . ';';
} else {
return $utf8;
}
}
示例9: make_confusing
public static function make_confusing($string)
{
$chars = str_split($string);
foreach ($chars as &$c) {
if (rand(0, 2) != 0) {
continue;
}
$c = mb_encode_numericentity($c, array(0, 0xffff, 0, 0xffff), 'UTF-8');
}
return implode('', $chars);
}
示例10: make_confusing
public static function make_confusing($string)
{
$chars = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
foreach ($chars as &$c) {
if (mt_rand(0, 3) != 0) {
$c = utf8tohtml($c);
} else {
$c = mb_encode_numericentity($c, array(0, 0xffff, 0, 0xffff), 'UTF-8');
}
}
return implode('', $chars);
}
示例11: process
/**
* Process contents i.e. insert DropCap at the beginning of the text.
*
* @param string $content The content to be processed
* @param array $options Array of options of how to filter dropcaps
*
* @return string The processed content
*/
public function process($content, $options)
{
// Initialize variables for titling
$titling = $options->get('titling.enabled');
$id = md5($content);
$breakpoints = preg_quote($options->get('titling.breakpoints'), '~');
$regex = "~.+?(?<=)[{$breakpoints}](?=\\s\\w|\\s*\$)~is";
// Load PHP built-in DOMDocument class
if (($dom = $this->loadDOMDocument($content)) === null) {
return $content;
}
// Create a DOM XPath object
$xpath = new \DOMXPath($dom);
// Get first paragraph of body element
$paragraph = $xpath->evaluate('body/p[1]')->item(0);
// A paragraph should have at least one node with non-empty content
if (!$paragraph || !$paragraph->hasChildNodes()) {
return $content;
}
$textContent = '';
$convmap = array(0x80, 0xffff, 0, 0xffff);
foreach ($paragraph->childNodes as $node) {
if ($node instanceof \DOMText) {
// Make sure that content is UTF-8 and entities properly encoded
$text = htmlspecialchars($node->textContent);
$text = mb_encode_numericentity($text, $convmap, 'UTF-8');
$textContent .= $text;
// Check to match a breakpoint
if (preg_match($regex, $textContent, $match)) {
$textContent = $match[0];
break;
}
} else {
// Add placeholder to text
$textContent .= "{$id}";
}
// No breakpoint found...
if ($paragraph->lastChild === $node) {
return $content;
}
}
// Replace placeholder with regex for matching a XML/HTML tag
$re = str_replace("{$id}", '\\s*<\\w+[^>]*>.*?', preg_quote($textContent, '~'));
$re = '~(<p[^>]*>)\\s*(' . $re . ')~is';
// Do content replacement
$content = preg_replace_callback($re, function ($match) use($paragraph, $options, $debugger) {
$content = $this->insertDropCap($match[2]);
list($tag, $content) = $this->insertTitling($paragraph, $content, $options->get('titling'));
return $tag . $content;
}, $content, 1);
// Write content back to page
return $content;
}
示例12: properText
function properText($text)
{
# detect if the string was passed in as unicode
$text_encoding = mb_detect_encoding($text, 'UTF-8, ISO-8859-1');
# make sure it's in unicode
if ($text_encoding != 'UTF-8') {
$text = mb_convert_encoding($text, 'UTF-8', $text_encoding);
}
# html numerically-escape everything (&#[dec];)
$text = mb_encode_numericentity($text, array(0x0, 0xffff, 0, 0xffff), 'UTF-8');
return $text;
}
示例13: utf16Urlencode
static function utf16Urlencode($str)
{
# convert characters > 255 into HTML entities
$convmap = array(0xff, 0x2ffff, 0, 0xffff);
$str = mb_encode_numericentity($str, $convmap, "UTF-8");
# escape HTML entities, so they are not urlencoded
$str = preg_replace('/&#([0-9a-fA-F]{2,5});/i', 'mark\\1mark', $str);
$str = urlencode($str);
# now convert escaped entities into unicode url syntax
$str = preg_replace('/mark([0-9a-fA-F]{2,5})mark/i', '%u\\1', $str);
return $str;
}
示例14: encode
public static function encode($value)
{
@mb_internal_encoding("UTF-8");
if (is_int($value)) {
return (string) $value;
} elseif (is_string($value)) {
$value = str_replace(array('\\', '/', '"', "\r", "\n", "\\b", "\f", "\t"), array('\\\\', '\\/', '\\"', '\\r', '\\n', '\\b', '\\f', '\\t'), $value);
$convmap = array(0x80, 0xffff, 0, 0xffff);
$result = "";
for ($i = @mb_strlen($value) - 1; $i >= 0; $i--) {
$mb_char = @mb_substr($value, $i, 1);
if (@mb_ereg("&#(\\d+);", @mb_encode_numericentity($mb_char, $convmap, "UTF-8"), $match)) {
$result = sprintf("\\u%04x", $match[1]) . $result;
} else {
$result = $mb_char . $result;
}
}
return '"' . $result . '"';
} elseif (is_float($value)) {
return str_replace(",", ".", $value);
} elseif (is_null($value)) {
return 'null';
} elseif (is_bool($value)) {
return $value ? 'true' : 'false';
} elseif (is_array($value)) {
$with_keys = false;
$n = count($value);
for ($i = 0, reset($value); $i < $n; $i++, next($value)) {
if (key($value) !== $i) {
$with_keys = true;
break;
}
}
} elseif (is_object($value)) {
$with_keys = true;
} else {
return '';
}
$result = array();
if ($with_keys) {
foreach ($value as $key => $v) {
$result[] = self::encode((string) $key) . ':' . self::encode($v);
}
return '{' . implode(',', $result) . '}';
} else {
foreach ($value as $key => $v) {
$result[] = self::encode($v);
}
return '[' . implode(',', $result) . ']';
}
}
示例15: _escape
protected static function _escape($value, $encoding = null)
{
$encoding or $encoding = self::_detectEncoding($value);
if ($encoding === 'UTF-8') {
# when possible force invisible characters to have some sort of display
$value = preg_replace('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x80-\\x9F]/u', '�', $value);
}
$value = htmlspecialchars($value, ENT_QUOTES);
if (function_exists('mb_encode_numericentity')) {
return mb_encode_numericentity($value, array(0x80, 0xffff, 0, 0xffff), $encoding);
} else {
return $value;
}
}