====== PHP javascript string filter ====== **Goal**: I want to have a javascript onclick function that will transfer data from an old data field to a new data field in a form when I click on ''<<'':
Comment?>
**Problem**: Some of the comments have NewLine (LF) characters in them. PHP just ignores NewLine characters; javascript treats them as line-enders and complains that the string lacks a closing single quote ("unterminated string literal"), so the transfer doesn't take place. Untitled Document
test Joe
**Solution**: I don't know exactly what characters MySQL allows in data fields. I couldn't find a script that would parse input from the data field and insert the javascript escapes, so I decided to bite the bullet and write my own. I got the list of javascript escape characters from [[http://html.megalink.com/programmer/jstut/jsTabChars.html|this page]]. I'm quite confident that others have already done this. :-( Oh, well--now I think I've got what I need, plus a little more awareness of what it takes to make PHP and javascript work together. PHP javascript string filter '; // fixed font format $s = chr(0x5C).': Backslash
'; echo (strJavaSafe($s)); $s = chr(0x08).': Backspace
'; echo (strJavaSafe($s)); $s = chr(0x09).': Tab
'; echo (strJavaSafe($s)); $s = chr(0x0A).': New line (LF)
'; echo (strJavaSafe($s)); $s = chr(0x0C).': Form Feed
'; echo (strJavaSafe($s)); $s = chr(0x0D).': Carriage Return
'; echo (strJavaSafe($s)); $s = chr(0x22).': Double Quote
'; echo (strJavaSafe($s)); $s = chr(0x27).': Single Quote '; echo (strJavaSafe($s)); echo ''; ?>