php dump into html file
i am new to php and i wanted to know if anyone can help me out with this issue. i have a table with various IDs, and for each ID i run a php script to show the contents associated with it, on a webpage. however, i would like to run a "generate_html_files.php" script to take each ID, get the HTML associated with its content and create an HTML file with that content.
i don't request a complete solution (i won't say no if you have one) but if one of you guys can point me into the right direction, i would appreciate it.
Check out file_put_contents() which will write anything to a file.
thanks, the issue that i have is not how to write to a file, it's executing a php script and getting its output as a string to be added to the file
Oh! I see. In that case, I guess it depends on your code.
One way could be, instead of echo-ing all your output, keep appending the strings from your statements to a variable (using .= for example), then at the end, echo the variable and write it to the file.
Another way could be to use output buffering, where you still echo everything, but it's recorded to a variable instead, so then you echo the variable and write it to the file.
If you have an existing script, you could stick an ob_start() at the top of it, then use an ob_get_clean() (or ob_get_flush() if you want to also display the page) at the end to save the output to a variable, which you could then write with file_put_contents().
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
thanks, i'll give that a try
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)