如何在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);

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

或者您可以尝试使用addcslasms,它更适合(您可以定义一个要转义的参数列表)。

最新更新