/    Sign up×
Community /Pin to ProfileBookmark

php dump into html file

hi all,
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.
cheers

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@weenisOct 25.2009 — Check out [url=http://us3.php.net/manual/en/function.file-put-contents.php]file_put_contents()[/url] which will write anything to a file. ?
Copy linkTweet thisAlerts:
@spectatorauthorOct 25.2009 — 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
Copy linkTweet thisAlerts:
@weenisOct 25.2009 — 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 [url=http://www.php.net/manual/en/ref.outcontrol.php]output buffering[/url], 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.
Copy linkTweet thisAlerts:
@NogDogOct 25.2009 — 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().
Copy linkTweet thisAlerts:
@spectatorauthorOct 25.2009 — thanks, i'll give that a try
×

Success!

Help @spectator spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...