Can anybody tell me how to read and output just the first line of a text file?
On the first iteration of the "while" loop below I need to extract the URL CarOne.jpg from the CarPictures.txt file. On the second iteration of the "while" loop I need to extract the HouseOne.jpg URL from the HousePicture.txt file. One the third iteration of the "while" loop I need to extract the BookOne.jpg URL from the BookPictures.txt file.
Right now I can get the filesystem functions to extract the URL's from the text files. However, the code below extracts all three URL's from each of the text files on each iteration of the "while" loop.
// $Variable = CarPictures.txt
CarOne.jpg // Need only this URL on 1st iteration.
CarTwo.jpg
CarThree.jpg
// $Variable = HousePictures.txt
HouseOne.jpg // Need only this URL on 2nd iteration.
HouseTwo.jpg
HouseThree.jpg
// $Variable = BookPictures.txt
BookOne.jpg // Need only this URL on 3rd iteration.
BookTwo.jpg
BookThree.jpg
while ($Row = mysql_fetch_array ($Result)){
$Variable = "".$Row["PictureFileColumn"]."";
// The snippet below extract all three picture URL's on
// each loop - I need for it to extract only the first
// picture URL on each iteration.
$TheFile = "./folders/$Variable";
$Open = fopen ($TheFile, "r");
if ($Open) {
$Data = file ($TheFile);
$Data[0];
echo $Data; // This outputs all three URLs on each iteration.
// I need for it to output only the first line of each text file.
}
fclose ($Open);
}// End of "while" loop.