Trouble using heredoc to store a php file as a string
Posted: Thu Oct 13, 2011 6:31 pm
I got the following example of heredoc from: http://tuxradar.com/practicalphp/2/6/3
It works fine, but I want to use heredoc to store a string starting with <?php so I can write it to a file as a .php page.
This code outputs the same as the last example above in spite of my addition:
How can I keep the <?php ...?> content as well so that I can use it to output a php page? I've done quite a bit of searching but noone seems to be using it in this way and the examples don't address this usage scenario.
Many thanks!
Ten
Code: Select all
$mystring = <<<EOT
This is some PHP text.
It is completely free
I can use "double quotes"
and 'single quotes',
plus $variables too, which will
be properly converted to their values,
you can even type EOT, as long as it
is not alone on a line, like this:
EOT;This code outputs the same as the last example above in spite of my addition:
Code: Select all
$mystring = <<<EOT
<?php echo "Welcome to my PHP page"; ?>
It is completely free
I can use "double quotes"
and 'single quotes',
plus $variables too, which will
be properly converted to their values,
you can even type EOT, as long as it
is not alone on a line, like this:
EOT;Many thanks!
Ten