开发者

Strip quotes in PHP for JSON output

开发者 https://www.devze.com 2023-02-20 09:20 出处:网络
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开发者_StackOverflow

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

精彩评论

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