php - read file and show the content

Hi E's, I need to know how I read a .htm file and show the contain line by line?

The best regards, JC
LVL 4
Pedro ChagasWebmasterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberstalkerCommented:
echo file_get_contents('filename here');
Pedro ChagasWebmasterAuthor Commented:
Thanks @cyberstalker,
It's possible put the data in array, like each line in array?

The best regards, JC
cyberstalkerCommented:
Yes. Just take the output from file_get_contents (which will return a string with all the contents) and explode it on newlines.

$lines = explode("\n", file_get_contents('filename here'));
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Hugh McCurdyCommented:
Does cyberstalker's reply answer your question or do you need more help?
Pedro ChagasWebmasterAuthor Commented:
Hi again, just one thing for finish:
I get the last code of @cyberstalker, and they work well, the script give me each line in differente arrays.
The problem is when I show the array, the data appear like the real site, if I have a link, appear the link but not the code.
You can check in the attach image.
How I can see the real code of the file?

Regards, JC
<?php
$lines = explode("\n", file_get_contents('indexes.htm')); ?>
<pre> 
<?
print_r($lines);
?>
</pre>

Open in new window

04-10-2011-19-17-29.png
cyberstalkerCommented:
What you need to do is escape the html code. For that, PHP has the htmlspecialchars function.

$lines = explode("\n", htmlspecialchars(file_get_contents('indexes.htm')));
Pedro ChagasWebmasterAuthor Commented:
In this case, if I want write other file with the code I get from the old file, I can?

Regards, JC
cyberstalkerCommented:
No, since the file will be escaped. If that is your intention, it would be better to escape it before showing.
<?php
$lines = explode("\n", file_get_contents('indexes.htm')); ?>
<pre> 
<?
print_r(array_map("htmlspecialchars", $lines));
?>
</pre>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.