How to convert Unicode NCR form to its original form in PHP? -


To avoid "monster characters", I want to store Unicode NCR form in non-English letters in the database (MySQL) Choose for However, the PDF plugin I use (FPDF) does not accept the Unicode NCR form as the correct format; It directly displays the data:

  and # 36889; & Amp; # 20491; & Amp; # 19968; & # 20491; & Amp; # 20363; & Amp; # 23376;  

But I want to show it:

這個 一個 例子

Is there any way to convert Unicode NCR form to its original form? ?

ps is the meaning of the sentence "This is an example" in traditional Chinese.

p.s I know the NCR destroys the farm's storage space, but it is the safest way to store non-English letters. correct me if I am wrong. Thank you.

PHP is a simple solution using the mbstring extension.

convert any decimal NCR to Unicode characters string = "& # 36889; & # 20491; & # 19968; & amp; # 20491; & amp; ; # 20363; & # 23,376; "; $ Output = preg_replace_callback ('/ (& # [0-9] +;) / u', function ($ m) {return utf8_entity_decode ($ m [1]);}, $ string); $ Output echo; Callback function {$ convmap = array (0x0, 0x10000, 0, 0xfffff) for // 這個 一個 例子 // regex function utf8_entity_decode ($ unit); Return mb_decode_numericentity ($ unit, $ convmap, 'UTF-8'); }

The 'utf8_entity_decode' function is from PHP.net (Andrew Simpson):. I changed the code a bit to avoid degraded 'A'-modifier inside Regex.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -