bcamp1973 Posted June 1, 2006 Share Posted June 1, 2006 I want to pass variables (primarily text strings) to a couple javascript functions. However, there are several characters that javascript gets hung up on including parenthesis, commas, double and single quotes etc. What all do i need to escape beyond that? also, what's the best method for escaping these characters? str_replace() seems a bit cumbersome...is there something more efficient? Quote Link to comment https://forums.phpfreaks.com/topic/10976-passing-variables-to-javascript/ Share on other sites More sharing options...
poirot Posted June 1, 2006 Share Posted June 1, 2006 If the variables are text strings, enclose them in quotes (echo 'var = \'$variable\'';) and everything should be fine.And you can also use addslashes() or htmlentities with ENT_QUOTES if you want to escape or convert quotes. Quote Link to comment https://forums.phpfreaks.com/topic/10976-passing-variables-to-javascript/#findComment-40992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.