I’m trying to write the equivalent of Rails escape_javascript() in php with a preg_match()
Is there any php built in function ?
Can someone help ?
# File actionpack/lib/action_view/helpers/javascript_helper.rb, line 50
def escape_javascript(javascript)
if javascript
javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] }
else
''
end
end
Thanks !
json_encode()
I can’t say that it’s a one-to-one match, but it’s a straightforward way to escape JavaScript values in PHP.