www.webdeveloper.com
Results 1 to 6 of 6

Thread: php dump into html file

  1. #1
    Join Date
    Oct 2009
    Location
    Saint Louis
    Posts
    6

    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

  2. #2
    Join Date
    Oct 2009
    Location
    Michigan
    Posts
    19
    Check out file_put_contents() which will write anything to a file.

  3. #3
    Join Date
    Oct 2009
    Location
    Saint Louis
    Posts
    6
    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

  4. #4
    Join Date
    Oct 2009
    Location
    Michigan
    Posts
    19
    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.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    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

    eBookworm.us

  6. #6
    Join Date
    Oct 2009
    Location
    Saint Louis
    Posts
    6
    thanks, i'll give that a try

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles