Click to See Complete Forum and Search --> : Using a HERE-document to write large blocks of text to a file


vi5in
08-25-2006, 04:54 AM
I'm writing a PHP script (that will be run through cron) that will "archive" my blog. Currently all my entries are in a database. I'm writing this script to pull the data out and put them into an actual file. My site displays the entries from the database and so I already have a layout designed. I'd like to preserve this layout when I create these files. So essentially I'm going to use an existing PHP page as a base. What it comes down to, is that I will need to output a large amount of text to a file. How can I do this with PHP? In perl I know you can use a HERE-document along with a file handle to output large blocks of text. How can I do something similar in PHP? Thanks.

vi5in
08-25-2006, 05:01 AM
Well, I figured it out.

I can do:

$large_txt = <<<TEXT

...text here

TEXT;

and then write that to the file.

bokeh
08-25-2006, 05:13 AM
heredoc is just a string feature and has nothing to do with saving to file.