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

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.