NYCPHP Meetup

NYPHP.org

[nycphp-talk] What's the best way to escape JavaScript data?

Rahmin Pavlovic rahmin at insite-out.com
Tue Jul 10 16:05:42 EDT 2007


Chuck Hagenbuch wrote:

> Quoting Cliff Hirsch <cliff at pinestream.com>:
> 
>> What is the best way to escape JavaScript data?
> 
> http://php.net/json-encode
> 

json_encode() loosely takes PHP data types and converts it to JavaScript
Object Notation (JSON) -- it actually doesn't escape the data itself that
well.

It depends on your app -- you may want to retain HTML tags, for example --
but I tend to trim, remove all UNIX chars, strip HTML tags and convert to
HTML entities.





More information about the talk mailing list