Mr_Chimp
Mr_Chimp

Reputation: 6907

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, newlines 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?

Upvotes: 0

Views: 2696

Answers (1)

TRiG
TRiG

Reputation: 10643

json_encode() will handle all that for you.

Upvotes: 5

Related Questions