I'm just learning php, and I am trying to parse some files I have, and then send the information to javascript. This is my php:
$datesArray = readFile();
echo json_encode($datesArray);
This echoes:
["120102000000","120102000500","120102001000","120102001500","120102002000","120102002500","120102003000"]
Which is what I want. However, my javascript, which looks like this:
var dates = <?php echo json_encode($datesArray); ?>;
console.log(dates);
keeps giving dates
back as null, and I am not sure why. I have tried encoding the array as utf-8, and I have tried using jQuery.parseJSON
which also did not work.
Thanks--
<?= json_encode($datesArray ?>;
– Seiyria May 5 at 17:46var dates <?= json_encode($datesArray) ?>;
? I keep getting a syntax error back :/ – user3605205 May 5 at 17:56var dates = ;
. How do I tell Javascript how to interpret the<?php ?>
tags? – user3605205 May 5 at 18:15