2009/5/21 Chris Sansom <ch...@highway57.co.uk>: > > At 17:24 +0300 21/5/09, Vladimir Tkach wrote: >>Prototype gsub error? >> >>$H({s:'\'}).toJSON() >> >>Result : SyntaxError: unterminated string literal > > I /think/, though the experts hereabouts will confirm or otherwise, > that JavaScript thinks the \ is escaping the quote that comes after > it. To do what you want, I believe you'd have to escape the backslash > in turn: > > $H({s:'\\'}).toJSON() > > I hope that's right! > > -- > Cheers... Chris > Highway 57 Web Development -- http://highway57.co.uk/ > > Why do you necessarily have to be wrong just because > a few million people think you are? > -- Frank Zappa > > > >
Yep. \ is a magic character in many languages. \r \n \t to name just 3 things (return, newline, tab). \\ is to allow the escape character through. Watch out when building JS code from other languages. <?php $s_JavaScriptString = 'document.write(\'John O\\\'Connor\');'; echo $s_JavaScriptString; ?> for example. Ok. Bad example, but as you start passing the text through different engines, the \ needs to be escaped for each level. So, PHP generating JS generating HTML content ... having anything to escape has to be done carefully. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---