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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求数据集和代码#有偿答复
    • ¥15 关于下拉菜单选项关联的问题
    • ¥20 java-OJ-健康体检
    • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
    • ¥15 使用phpstudy在云服务器上搭建个人网站
    • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
    • ¥15 vue3+express部署到nginx
    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
    • ¥15 画两个图 python或R