Page 1 of 1

Need to write a html output in a file

Posted: Thu Aug 20, 2009 5:23 am
by jayarajmohan
Hi all,

I need to write a html output to the text file.

For ex.
<?php
$str = "<html><body><table><tr><td>fjlhfg</td><td>dsdsdf</td></tr></table></body></html>";

$myFile = "report.txt";
$fh = fopen($myFile, 'w') or die("can't open file");

echo $str;
fwrite($fh, $str);
fclose($fh);
?>

Here the out put of the report.txt is "<html><body><table><tr><td>fjlhfg</td><td>dsdsdf</td></tr></table></body></html>"

But while we run this in browser it shows like "fjlhfg dsdsdf"

I need to write the browser output to a file (as like fjlhfg dsdsdf)..

Any idea's welcome....

Thanks..

Re: Need to write a html output in a file

Posted: Thu Aug 20, 2009 7:57 am
by jackpf
I'm not entirely sure what you mean...but is it strip_tags() you want?

Re: Need to write a html output in a file

Posted: Thu Aug 20, 2009 8:09 am
by jayarajmohan
Yes you come near to my requirements.

strip_tags() function is exclude the html and php tags.

But i want the exact html out put as like displayed in browser.

Like :
$str = "abc<br>dfg";

echo $str;

// output is
abc
dfg

The same output i want to write in a text file. note like abcdfg (strip_tags this works like this)

I hope u got my point..

Thanks

Re: Need to write a html output in a file

Posted: Thu Aug 20, 2009 8:13 am
by jackpf
Well, you can't have complete html formatting in a text file.

There are functions you can use though...

To convert <br /> tags to new lines, you could do this:

Code: Select all

$str = str_replace('<br />', "\n", $str);
Stuff like that.

Re: Need to write a html output in a file

Posted: Thu Aug 20, 2009 8:23 am
by jayarajmohan
Okay thank you for your ideas...

JayaraJMohan.J

Re: Need to write a html output in a file

Posted: Thu Aug 20, 2009 1:56 pm
by alex.barylski
It's displayed like in the browser because the tags are rendered...if I understand ylu correctly you maybe want htmlentities() so the text appears as full source code when viewed in the browser???

Re: Need to write a html output in a file

Posted: Thu Aug 20, 2009 2:13 pm
by Benjamin
:arrow: Moved to PHP - Code