百科狗-知识改变命运!
--

mb_encode_numericentity() - mb函数(多字节字符串转化库)

乐乐12个月前 (11-21)阅读数 12#技术干货
文章标签字符

mb_encode_numericentity()

(PHP 4 >= 4.0.6, PHP 5, PHP 7)

Encode character to HTML numeric string reference

说明

mb_encode_numericentity(string $str,array $convmap[,string $encoding= mb_internal_encoding()[,bool $is_hex= FALSE]]): string

Converts specified character codes in string$strfrom character code to HTML numeric character reference.

参数

$str

The string being encoded.

$convmap

$convmapis array specifies code area to convert.

$encoding

$encoding参数为字符编码。如果省略,则使用内部字符编码。

$is_hex

Whether the returned entity reference should be in hexadecimal notation(otherwise it is in decimal notation).

返回值

The converted string.

更新日志

版本说明
5.4.0 Added$is_hexparameter.

范例

mb_encode_numericentity() - mb函数(多字节字符串转化库)

Example #1$convmapexample

范例

mb_encode_numericentity() example

参见

  • mb_decode_numericentity()根据 HTML 数字字符串解码成字符
To get Unicode numbers out of a UTF-8 string, this can be used, for example: 
To improve handling of EURO-Symbols in dan at boxuk dot com's function add the following line to $convmap:
128,128,0, $f,
Here is a better explanation of convmap:
https://stackoverflow.com/questions/35854535/better-explanation-of-convmap-in-mb-encode-numericentity
We were experiencing difficulties with PHP/Sablotron on Solaris; placing HTML character references into the XSL transformation, when set to output UTF-8, converts them back into UTF8 encoded chars. This was then a problem for non unicode storage. Using a bit of code from http://homepage.mac.com/marko/ the following function converts the string back to character references:
function utf2html ($utf2html_string)
{
  $f = 0xffff;
  $convmap = array(
/* 
  %HTMLlat1; */
   160, 255, 0, $f,
/* 
  %HTMLsymbol; */
   402, 402, 0, $f, 913, 929, 0, $f, 931, 937, 0, $f,
   945, 969, 0, $f, 977, 978, 0, $f, 982, 982, 0, $f,
  8226, 8226, 0, $f, 8230, 8230, 0, $f, 8242, 8243, 0, $f,
  8254, 8254, 0, $f, 8260, 8260, 0, $f, 8465, 8465, 0, $f,
  8472, 8472, 0, $f, 8476, 8476, 0, $f, 8482, 8482, 0, $f,
  8501, 8501, 0, $f, 8592, 8596, 0, $f, 8629, 8629, 0, $f,
  8656, 8660, 0, $f, 8704, 8704, 0, $f, 8706, 8707, 0, $f,
  8709, 8709, 0, $f, 8711, 8713, 0, $f, 8715, 8715, 0, $f,
  8719, 8719, 0, $f, 8721, 8722, 0, $f, 8727, 8727, 0, $f,
  8730, 8730, 0, $f, 8733, 8734, 0, $f, 8736, 8736, 0, $f,
  8743, 8747, 0, $f, 8756, 8756, 0, $f, 8764, 8764, 0, $f,
  8773, 8773, 0, $f, 8776, 8776, 0, $f, 8800, 8801, 0, $f,
  8804, 8805, 0, $f, 8834, 8836, 0, $f, 8838, 8839, 0, $f,
  8853, 8853, 0, $f, 8855, 8855, 0, $f, 8869, 8869, 0, $f,
  8901, 8901, 0, $f, 8968, 8971, 0, $f, 9001, 9002, 0, $f,
  9674, 9674, 0, $f, 9824, 9824, 0, $f, 9827, 9827, 0, $f,
  9829, 9830, 0, $f,
/* 
  %HTMLspecial; */
/* These ones are excluded to enable HTML: 34, 38, 60, 62 */
   338, 339, 0, $f, 352, 353, 0, $f, 376, 376, 0, $f,
   710, 710, 0, $f, 732, 732, 0, $f, 8194, 8195, 0, $f,
  8201, 8201, 0, $f, 8204, 8207, 0, $f, 8211, 8212, 0, $f,
  8216, 8218, 0, $f, 8218, 8218, 0, $f, 8220, 8222, 0, $f,
  8224, 8225, 0, $f, 8240, 8240, 0, $f, 8249, 8250, 0, $f,
  8364, 8364, 0, $f);
  return mb_encode_numericentity($utf2html_string, $convmap, "UTF-8");
}

鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com

免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)

图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)