I’m using fgets to read a file line by line. Certain string combinations are being ignored. I’m guessing this is being picked up as an escape character, but I don’t understand.
My code is:
$myFile = $_GET['filename'];
$file = fopen($myFile, "r");
while (!feof($file))
{
$currentLine = fgets($file);
print $currentLine;
}
And my file is:
15:37:33 Me <Washington USA> outdoor
15:39:34 Me <Washington USA> outdoor
15:41:36 Me <208 Terrace Ct SE USA> outdoor
15:43:37 Me <305 Glyndon St SE USA> indoor
Yet the output is only this:
15:37:33 me outdoor 15:39:34 me outdoor 15:41:36 me <208 Terrace Ct SE USA> outdoor 15:43:37 me <305 Glyndon St SE USA> indoor
Why are the <‘s followed by characters ignored but not the <‘s followed by numbers?
The browser interprets the text between < and > as an HTML tag (at least the ones that don’t start with a digit). If you look at the source of your page, I’m sure you’ll find the complete text.
To solve your issue, use PHP’s htmlentities() function like this:
http://ch2.php.net/manual/en/function.htmlentities.php