Jump to content

FEOF Behavior problem?


everettcomstock

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.