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 3
Pedro ChagasWebmasterAsked:
Who is Participating?
 
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

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

The best regards, JC
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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'));
0
 
Hugh McCurdyCommented:
Does cyberstalker's reply answer your question or do you need more help?
0
 
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
0
 
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')));
0
 
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.