[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

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
0
Pedro Chagas
Asked:
Pedro Chagas
  • 4
  • 3
4 Solutions
 
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now