Need HTML file format dynamically.

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
inpreet
Forum Newbie
Posts: 4
Joined: Fri Jul 16, 2004 12:48 am

Need HTML file format dynamically.

Post by inpreet »

I am bulding an application which take HTML format as input and generate PDF files as output. This library, I am using for reporting purpose. Now the problem is, I need to get data dynamically using PHP from database which ultimately will return HTML format after returning from PHP engine. Now how can I get this dynamically generated HTML file. So that I can make it as input to my library for report generation.

I hope clearly explained my requirement.

Thanks in advance.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

the easiest way but not neccesarily the most effiecient is to assign all of the dynamic html document to a php variable then just echo out the variable.

Code: Select all

<?php
$html = "<html><head><title>$myPageTitle</title></head>";
$html .= "<body>$text_generated_eailer</bocy></html>";
echo $html;
?>
As well then if you are generatin your pdf file at the same time you can just use the $html var.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Is it a php library to make the pdf?

Several things you can do, some more pratical than others - but they all revolve around running the page in some form or another. First simple way is to simply run the php page in a browser and save the output. This will get annoying if your makeing hundreds of pages. Simple way to speed it up would be to use a script to run curl to save the output:

Code: Select all

curl -O http://www.something.com
etc.

Then if the pdf library is in php you can have it all done on a single page by buffering the output of the php and passing that to the library. Either buffer it yourself or use start_ob() and related functions.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

You could also convert your html page into templates, then use a template engine to parse (but not output) the template using the dynamic data and pass the resulting string to your PDF library.

It's a variation on your first response, but each depends on how you generally generate your output at present...stick with what you know unless you have a good reason to change...
Post Reply