在PHP中从原始文本文件中读取时保留标记

I have a simple text file. The content has xml tags. The issue with that is some of the elements don't have closing tags.

I am able to read the file in line by line, however the tags are missing when I echo back what was read.

Sample File Content.

<SOL>
<Name> JJ Evans
<Address> 1010 Good Times Lane
</Sol>

When I read this file, line by line and echo out the output I get:

JJ Evans
1010 Good Times Lane

I need the output to be:

<SOL>
<Name> JJ Evans
<Address> 1010 Good Times Lane
</Sol>

And help resolving this would be appreciated.

Try using htmlentities() on each line, it won't let the browser parse the tags. Also if you don't have any particular need to read the file line-by-line, you better stick with file_get_contents(), just call htmlentities(file_get_contents('sample.xml')) and you'll make the job even easier.