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? 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. Link to comment https://forums.phpfreaks.com/topic/10976-passing-variables-to-javascript/#findComment-40992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.