everettcomstock Posted November 20, 2006 Share Posted November 20, 2006 Hi Everyone, I posted to this forum earlier this evening and I was instantly helped by numerous people. Thanks again for your time. I am now noticing some odd behavior from the script that I am attempting to write. It is acting as if it is "timing out" or possibly reaching the FEOF in different parts of the script. Specifically, the script starts a Foreach loop that outputs the variables of an array to the screen. When I refresh the page it may output 275 values or it may output 308 values. The input varibles do not change but the amount of output seems to be random (Between 275 and the entire file output). I ave checked my PHP.ini, and I do not believe the script is timing out, but I have not ruled out that possibility. I believe the FEOF is being reached because I have multiple fields where there is no data in the file. Here is the script, and if you have any thoughts, I would love to hear them. Thanks!<?php$file = "playlist.txt";$fileopen = fopen($file,"r");$filearray = array(); while (!feof($fileopen)) { $temp = fgets($fileopen); $trimtemp = trim($temp); if (!empty($trimtemp)) $filearray[] = $trimtemp; } foreach ($filearray as $key => $value){ echo"$key - $value <br>"; } fclose($fileopen);?> example output:0 - 1 - !!!Otter Radio Rocks!!! 2 - ...And You Will Know Us by the Trail of Dead 3 - 10,000 Maniacs 4 - 30 Seconds To Mars 5 - 30 Seconds to Mars 6 - 311 7 - 3rd Bass 8 - A Perfect Circle 9 - A Tribe Called Quest 10 - Aaliyah 11 - Aaliyah feat. DMX 12 - Aaron Lewis/Sevendust 13 - Afroskull 14 - All Mighty Senators 15 - American Football 16 - Archie Eversole 17 - Art Tatum 18 - Ashanti ............................And So On............. Link to comment https://forums.phpfreaks.com/topic/27848-feof-behavior-problem/ Share on other sites More sharing options...
hitman6003 Posted November 21, 2006 Share Posted November 21, 2006 If each of the artist names is on a seperate line in the file, why not use the file function:http://www.php.net/fileOr, use file_get_contents, then explode the string on the seperating character to create the array.http://www.php.net/file_get_contents Link to comment https://forums.phpfreaks.com/topic/27848-feof-behavior-problem/#findComment-127756 Share on other sites More sharing options...
everettcomstock Posted November 21, 2006 Author Share Posted November 21, 2006 Hi Hitman, I actually considered using the file() function, but the problem I encountered was that all of the empty lines in my original file were entered into the array. If you know of a way I could use that function, and strip all of the blank lines from my input text, I would appreicate the knowledge. I am currently using html like sperating characters to tag the information that is in the input file. If there is an artists name it is encased in <ARTIST></ARTIST>, or if it is a song it is encased in <SONG></SONG>. So... I believe I could use the file_get_contents function and possibly even trim the blank entries using the trim function. However, I am also unsure as to how I would then take the individual strings (ie."<ARTIST>311<?ARTIST>") and then build arrays suchas $artist[], $album[], and $song[].As always, much thanks for everyone who contributes to this forum. You guys are lifesavers for those of us who are still learning.Everett Link to comment https://forums.phpfreaks.com/topic/27848-feof-behavior-problem/#findComment-127889 Share on other sites More sharing options...
hitman6003 Posted November 22, 2006 Share Posted November 22, 2006 Just use an if statement when you loop through the results:[code]$file = file($filename);foreach ($file as $Line) { if (trim($line) != "") { //do your operations }}[/code] Link to comment https://forums.phpfreaks.com/topic/27848-feof-behavior-problem/#findComment-128246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.