I've been working on a personal project for a few days now, everything was working nicely, but since I've started on it again 2 hours ago I'm getting the following problem:
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php
$Testarray = array_map('str_getcsv', $content=file('Shows.csv'), array_fill(0,count($content), ";"));
foreach($Testarray as $array)
{
foreach($array as $item)
{
print($item);
print '<br/>';
}
}
?>
<script type="text/javascript">
var array = <?php echo json_encode($Testarray); ?>;
</script>
</body>
</html>
I'm allmost afraid to ask, but the 'var array' in Javascript is null. $Testarray is filled correctly, it prints the correct values. I've tried to do the same with a simple String and that works without a problem.
I've also tried var array = new Array(); prior to filling it. No effect.
Edit after trincot's reply:
var array = JSON.parse('<?php echo json_encode($Testarray); ?>');
Gives the following result in "Sources" in Chrome:
var array = JSON.parse(' ');
So it still doesn't seem to return anything.
Edit2: var_dump($testarray) (Sources in Chrome):
Final edit: The cause of the problem was a value in the xlsx file I exported from to a CSV file.
The xlsx had a value with the ô
character, which was replaced with �
in the CSV file. This caused for a nested null array in PHP and made everything go boom.
Using Eric's answer from another question, saving the xlsx file as xls and then saving the xls as CSV did the trick.