douba3975 2016-08-06 16:03
浏览 234

PHP:如何将格式json_encode模拟为包含html的文本

I have an array, this array fill with values from database, some of the value contains html tags.

I need to echo this array as json format, so I am using json_encode to do that.

The problem is, when I try to replicate json format (because I need the json to be simpler). I can not replicate value which have html tags.

example:

  • original value from database
 <span style='font-size:12px'> 25 - 35 " </span><p><span style='font-size:12px'> 
  </span>
  • after json_encode(this is what i want it to be)

25 - 35 \" </span> </span>

Thanks

  • 写回答

1条回答 默认 最新

  • dpjo15650 2016-08-12 03:03
    关注

    You could try using htmlentities() on each element before building your json string, but i would agree with commenters that you should just create a new array from your old one with only the values you want, then json_encode that.

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集