开发者

Strip quotes in PHP for JSON output

I have a string in PHP that contains both single and double quotes.

I am trying to use this string in some JSON output. To do this I need to escape double quotes, slashes, newline开发者_StackOverflows etc.

I thought that addslashes() would do the job but it also escapes single quotes which causes the JSON to fail.

How can I escape all relevant special characters except for single quotes?


json_encode() will handle all that for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜