slacker_x
04-13-2002, 04:53 AM
This script is going into an infinite loop on this line: while($line != ""). The final line in the text file is a blank line with a \n character. the rtrim should remove that and put an empty variable in the array. I thought it might be the emptiness that was causing the problem, so I terminated the messages with a "3" instead. Still the same infinite loop. Any idea why this is happening?
<?php
$fp = fopen("guestbook.txt", "r");
$file_array = array();
while(!feof($fp))
{
$buffer = fgets($fp, 8192);
if(!feof($fp))
{
$file_array[] = rtrim($buffer);
}
}
fclose($fp);
$message = array();
foreach($file_array as $line)
{
while($line != "")
{
$message[] = $line;
}
print("NAME: ".array_shift($message)."<br ?>\n");
print("EMAIL: ".array_shift($message)."<br ?>\n");
foreach($message as $msg_line)
{
print($msg_line);
}
}
?>
<?php
$fp = fopen("guestbook.txt", "r");
$file_array = array();
while(!feof($fp))
{
$buffer = fgets($fp, 8192);
if(!feof($fp))
{
$file_array[] = rtrim($buffer);
}
}
fclose($fp);
$message = array();
foreach($file_array as $line)
{
while($line != "")
{
$message[] = $line;
}
print("NAME: ".array_shift($message)."<br ?>\n");
print("EMAIL: ".array_shift($message)."<br ?>\n");
foreach($message as $msg_line)
{
print($msg_line);
}
}
?>