Hi there, Does anyone know how I can go about parsing a text file (with html tags) so that when I print() the contents, the output will include the html tags. For example: I have <?php $filename = "test.txt"; $fp = fopen($filename, "r") or die("Couldn't open $filename"); while (!feof($fp)){ $line = fgets($fp); echo $line; } ?> Code (markup): which prints out: but the contents of the "test.txt" is: Thanks heaps in advance. James
It's echoing everything, so within the page it is probably still spitting out the div tags. What you'll have to do is change the div tags to: <div> Code (markup): instead. That way it won't make it actual html, but text. You could do this with a string replace htmlentities like: <?php $filename = "test.txt"; $fp = fopen($filename, "r") or die("Couldn't open $filename"); while (!feof($fp)){ $line = fgets($fp); echo htmlentities($line); } ?> Code (markup):
may be you can use the second parameter of fgets. I used to fgets($f, 32000). And to read a file in cycle
@sdemidko the second parameter is used to tell fgets on how many bytes of data should it get per cycle, which won't solve the problem.