Hi all,
I'm trying to pass a PHP array into a javascript array. I know how to do this with a variable, just can't get the array to work without giving a js error when the page loads.
The PHP piece opens a file that contains lines with both text and <html> tags.
The PHP code snipet:
$handle = fopen ("somedir/subdir/" . $somefile . ".txt", "r");
while (!feof ($handle)) {
$theInfo[] = fgets($handle, 4096);
}
fclose ($handle);
The JavaScript code snipet (loading below the PHP piece):
var messages=new Array()
messages[0]= theImg //This loads no problem w/o the array below
<?php
echo("messages[1] = ".$theInfo[0].";");
?>
That JS code gives a "Syntax Error" when the page loads. If I debug it, it shows the array was loaded with the info from the file:
var messages=new Array()
messages[0]= theImg
messages[1] = <font color='red'>Test</font><br><font size='4' color='blue'>TESTING</font>;
I've tried using:
echo"("messages[1] = ".$theInfo[0].";");"
echo("messages[1] = "$theInfo[0]";");
echo(messages[1] = ".$theInfo[0].");
All with no success.
It's having a problem with messages[1]
Does anyone have a snipet where they successfully pass a PHP array to a Javascript Array?
Thanks!