FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Heredoc print to file? Use nowdoc.
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Heredoc print to file? Use nowdoc. [message #172114] Mon, 31 January 2011 02:38 Go to previous message
P E Schoen is currently offline  P E Schoen
Messages: 86
Registered: January 2011
Karma:
Member
I ran into an issue with a heredoc that works in Perl, but apparently not in
PHP. I want to write the output of the heredoc to a file other than stdin,
which is done in Perl as:

print fOutput <<EOF ;
My Text
My HTML
EOF

and you can use

print <<EOF ;
...
EOF

for output (echo) to stdin.

But in PHP it is either:

print <<<EOF
...
EOF;

or

echo <<<EOF
...
EOF;

And there seems to be no way to do this. There is also a bug report/request
on the subtle behavior of the heredoc regarding whitespace:
http://bugs.php.net/bug.php?id=24750

But I found something called a nowdoc which might allow this:

$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;
fwrite( $fh, $str );

http://www.php.net/manual/en/language.types.string.php#language.types.strin g.syntax.heredoc

OK, that works. I have changed the subject to reflect it has been solved.
This is still a good reference for other newbies and Perlites.

I also tried using $stdout but it did not work, although the following seems
to hint that it might:
http://php.net/manual/en/features.commandline.io-streams.php

Paul
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: Unable to connect to database server!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 23:32:34 GMT 2024

Total time taken to generate the page: 0.04033 seconds