I'm trying to dump a PHP array to a JavaScript one. (without using any extra extensions) So far I've managed to make it dump the ID and titles of the text items it retrieves from the database but as soon as I try to dump the text item content the whole script breaks.
<script type="text/javascript">
var idList=new Array();
var titleList=new Array();
var contentList=new Array();
<?php
foreach($list["id"] as $index => $value)
{
$content = htmlentities($list["tekst"][$index], ENT_QUOTES);
echo('idList.push('.$list["id"][$index].');');
echo('titleList.push("'.$list["title"][$index].'");');
//echo('contentList.push("'.$content.'");');
}
?>
</script>
The line that breaks the whole script has been commented out. Here's one of the strings that is pushed to contentList:
<p>Ik ben onweer. ROMMELDEBOMMEL!</p>
<p>Ik ben donker en duister maar ook heel belangrijk voor de natuur.</p>
<p>ofzoiets... geen zin. lat0rzzzzzzzzzzzzzzzzzzzzzz</p>
It's in Dutch but I assume you get the point.
EDIT: I tried using a method suggested in the 'linebreaks' question but the code still breaks. Here's the code it outputs:
contentList.push("<p>Ik ben onweer. ROMMELDEBOMMEL!</p>"+
"<p>Ik ben donker en duister maar ook heel belangrijk voor de natuur.</p>"+
"<p>ofzoiets... geen zin. lat0rzzzzzzzzzzzzzzzzzzzzzz</p>");
EDIT #2: I noticed this error in my JS console "Uncaught SyntaxError: Unexpected token ILLEGAL"
EDIT #3: Switched to AJAX approach. Which makes this script obsolete. Thanks for the help guys. ;)