相关疑难解决方法(0)

是否有一个PHP函数只添加斜杠到双引号而不是单引号

我用PHP生成JSON.

我一直在用

$string = 'This string has "double quotes"';

echo addslashes($string);
Run Code Online (Sandbox Code Playgroud)

输出: This string has \" double quotes\"

完全有效的JSON

不幸的是,对于有效的JSON,addslashes也会逃避单引号,带来灾难性后果

$string = "This string has 'single quotes'";

echo addslashes($string);
Run Code Online (Sandbox Code Playgroud)

输出: This string has \'single quotes\'

简而言之,有没有办法只能逃避双引号?

php json

31
推荐指数
3
解决办法
3万
查看次数

标签 统计

json ×1

php ×1