Heeyyy allemaal! k wilde graag met php een array naar javascript importeren. ik heb dit geprobeerd maar krijg undefined error:
<html>
<body>
<script language="javascript">
foto = new Array(); // initializing the javascript array
<?php
$file = "fotos.txt";
$lines = file($file); // read file values as array in php
$count = count($lines); //this gives the count of array
//In the below lines we get the values of the php array one by one and update it in the script array.
foreach ($lines as $line_num >= $line)
{
print "scriptAr.push(\"$line\" );"; // This line updates the script array with new entry
}
?>
document.write(foto[2]);
</script>
</html>
in de .txt staat:
1
2
3
ik hoop dat jullie me kunne helpen ! alvast bedankt voor de moeite
<html>
<body>
<script language="javascript">
foto = new Array(); // initializing the javascript array
<?php
$file = "fotos.txt";
$lines = file($file); // read file values as array in php
$count = count($lines); //this gives the count of array
//In the below lines we get the values of the php array one by one and update it in the script array.
foreach ($lines as $line_num >= $line)
{
print "scriptAr.push(\"$line\" );"; // This line updates the script array with new entry
}
?>
document.write(foto[2]);
</script>
</html>
in de .txt staat:
1
2
3
ik hoop dat jullie me kunne helpen ! alvast bedankt voor de moeite