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

时间:2014-09-23 03:01:27

标签: php json

我想将数组转换为JSON。我的问题是该数组中的一个元素包含单引号,双引号等。

<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>

当我提交时,我得到了:

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

当我解码它时,我只得到了一部分字符串。

1 个答案:

答案 0 :(得分:0)

或许您可以尝试更适应的addcslashes(您可以定义要逃避的参数列表)。