doumo2501 2018-05-16 09:48
浏览 211

在PHP数组中将Unicode转换为HTML实体

I have issues with unicode characters returning a string null within an array. This array is creating in PHP and echoed which json_encode. The problem exists within "name".

The initial object looks like:

[{"ID":"147","First Name":"Tom","Last Name":"Bishai","Registered Table Number":"34","Email Address":"tombishai@gmail.com","Phone Number":"07921130704","Amount":"800","MadeFrom":"34","Type of Transaction":"bid","Number":"22","name":null,"Gift Aid":"Yes","PIN":"1261"}]

I have used a function from another question which looks like this:

    function utf8ize($d) {
      if(is_array($d)) {
        foreach($d as $k => $v) {
          $d[$k] = utf8ize($v);
        }
      }  else if(is_string($d)) {
        return utf8_encode($d);
      }
      return $d;
    }
echo json_encode(utf8ize($arr));

This now returns a string (within the array) which looks like:

[{"ID":"147","First Name":"Tom","Last Name":"Bishai","Registered Table Number":"34","Email Address":"tombishai@gmail.com","Phone Number":"07921130704","Amount":"800","MadeFrom":"34","Type of Transaction":"bid","Number":"22","name":"JOAN MIRO \u0096 COMPOSITION IX","Gift Aid":"Yes","PIN":"1261"}]

Now I am having trouble converting this to a html entity. It will also need to apply to any other unicode characters that may appear in the database. Any help?

Many thanks!

UPDATE: Just doesn't seem to work with em dash/en dash. I haven't gone through all of the unicode characters though.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)