doumei4964 2014-09-23 03:01
浏览 272

如何将数组转换为包含PHP中的双引号的json?

I want to convert an array into JSON. My problem is that one of that elements in that array contain single quotes, double quotes etc.

<textarea name="description" id="description">
   Tesla is the living definition of bad*** and mad scientist. 
   During Tesla's later years, he made claims concerning a 
   "teleforce" weapon after studying the Van de Graaff generator. 
   The press called it a "peace ray" or death ray. Tesla described 
   the weapon as being able to be used against ground-based infantry 
   or for antiaircraft purposes.
</textarea>

When I submit it I got:

$description = $_POST['description'];
json_encode($description);

When I decode it, I got only a part of string.

  • 写回答

1条回答 默认 最新

  • duanquan4451 2014-09-23 03:56
    关注

    Or maybe you could try with addcslashes, which is more adapted (you can define a list of parameters to escape).

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)