Need HTML output of the PHP file as String

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sathishkpm
Forum Newbie
Posts: 12
Joined: Fri Oct 13, 2006 8:28 am

Need HTML output of the PHP file as String

Post by sathishkpm »

Dear All,

I am working on the project to convert my web page into PDF file for that I am using dompdf, the dompdf wants the html text as string but my file is in php. Is there any possibility to get the output of the php file as a string format.

for example my code to convert html string into pdf is in 1.php, I need to have the html string as the html output of the 2.php, so is there any way to get the html output of the 2.php in 1.php as string?

Please help me in this regard,

Thanks in advance.

Regards,

Sathish Kumar :-)
adroit
Forum Commoner
Posts: 37
Joined: Fri Aug 08, 2008 1:25 am
Location: India
Contact:

Re: Need HTML output of the PHP file as String

Post by adroit »

Hi Friend,

You can do this
<?php
ob_start();
include("2.php")
$html = ob_get_contents();
ob_end_clean();

?>

Now the above $html variable will have the 2.php code in html/string format, you can pass this variable to the 1.php or can create any html page with $html variable as page content.

Regards
sathishkpm
Forum Newbie
Posts: 12
Joined: Fri Oct 13, 2006 8:28 am

Re: Need HTML output of the PHP file as String

Post by sathishkpm »

Hi adroit,

Thank you so much.. its working very fine..

Thanks a lot once again.

- Sathish :-)
Post Reply