[nycphp-talk] Passing JavaScript arrays
cliff
cliff at pinestream.com
Tue Jul 11 11:56:43 EDT 2006
Actually, this make perfect sense now. The code I inherited did nothing of the
sort and your explanation leads me to believe I have just been lucky so far.
On another note, I found a PEAR library that does basicly the same thing. I
don't take advantage of PEAR often enough, but looking at the code
(HTML_Javascript) makes me realize it usually accounts for things that I won't
realize until the gene hits.
Cliff
On Mon, 10 Jul 2006 14:57:37 -0400, Peter Sawczynec wrote
> No, I did not pass these as actual GET or POST data between web
> pages. This technique was a jury-rig technique to get strings of
> HTML and other odd characters safely into a client-side JavaScript
> array as follows:
>
> The data for the JavaScript slideshow array gets pulled from MySQL
> by PHP, then with PHP the urlencode($db_data) step ensures that no
> character element in the $db_data string (such as single-quote,
> double-quote, semi-colon or backslash) gets interpreted by the
> JavaScript as a command that might throw an error on the browser page.
>
> Then in the actual JavaScript I found that the combined JavaScript
> replace(unescape(<? echo $db_data ?>),'+',' ') nicely undoes the PHP
> urlencoding and ensures that when JavaScript pushes a data array
> string into the browser innerHTML element the string has a very high-
> chance of being cross-browser compatible and the display to the user
> is pretty.
>
> If this was not your technology issue, then forgive me for sending
> up this suggestion.
>
> Peter
More information about the talk
mailing list