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..
Need to write a html output in a file
Moderator: General Moderators
-
jayarajmohan
- Forum Newbie
- Posts: 16
- Joined: Fri Aug 29, 2008 12:06 am
Re: Need to write a html output in a file
I'm not entirely sure what you mean...but is it strip_tags() you want?
-
jayarajmohan
- Forum Newbie
- Posts: 16
- Joined: Fri Aug 29, 2008 12:06 am
Re: Need to write a html output in a file
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
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
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:
Stuff like that.
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);-
jayarajmohan
- Forum Newbie
- Posts: 16
- Joined: Fri Aug 29, 2008 12:06 am
Re: Need to write a html output in a file
Okay thank you for your ideas...
JayaraJMohan.J
JayaraJMohan.J
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Need to write a html output in a file
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???