I have a text file and each line of the file, I would like stored in a variable.
The text file has text strings on 5 separate lines. The following code only allows me to get anything stored in the first variable ($datespan = $data[0]; ). None of the other variables contain anything. I'm assuming I am not pulling each line into the array properly. Can someone help please? Thanks in advance.
This is my code:
<?php
$file = fopen('db/data.txt', 'r') or die('Could not read file!');
$data = array();
while (!feof($file))
{
$buf = fgets($file);
if ($buf === FALSE)
{
fclose($file);
}
$data[] = $buf;
}
$datespan = $data[0];
$title1 = $data[1];
$actors1 = $data[2];
$description1 = $data[3];
$image1 = $data[4];
fclose($file);
?>
I include the above file in test.php. Then test php accesses the variables with the following code. Only $datespan displays.
<!-- BODY -->
<h2><?php echo $datespan; ?></h2>
<br>
<h2><?php echo $title1; ?></h2>
<br>
<h2><?php echo $actors1; ?></h2>
<br>
<h2><?php echo $description1; ?></h2>
<br>
<h2><?php echo $image1; ?></h2>
<br>