I have some php code which I believe should read the lines of a text file into an array, and then display a JavaScript alert box sequentially showing each line of the file.
It works fine if I use line 11 (i.e. using a basic array), but does not work if I read lines from a file (line 10).
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="main">
<?php
//$text = file("C:\\Apache24\\htdocs\\release_notes_2.txt"); // line 10
$text = array('line 1', 'line 2', 'line 3', 'line 4', 'line 5'); // line 11
$it = 0;
foreach ($text as $line) {
echo "<script type='text/javascript'>alert('".$text[$it]."');</script>";
$it++;
}
?>
</div>
</body>
</html>
When I use line 10 instead of line 11, I only get one alert, and the alert message corresponds to the very last line of the file.
Why is this happening?
Note: I am using php version 7.0.14.