3

I'm using fgets to read a text file that contains field names delimited with the "<" and ">" characters. It seems like fgets is seeing these field names as tags and stripping them. I thought that only fgetss stripped tags and that fgets should allow this. I'm testing this with the following code:

<?php
$handle = @fopen("Test.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}
?>

My file is similar to this

filename.txt
Header test
<EOH>
<Field 1>Name<Field 2>Address<Field 3>Country<EOR>
<Field 1>Name<Field 2>Address<Field 3>Country<EOR>

Anyone know how I can retain my field names when reading text from file using fgets or similar. I tried using fgetss and specifying my field names as allowable tags but that didn't work, I guess because they aren't true html tags?

4

0 回答 0