I want to do output like this:
echo <<<END
$monkey
END;
where the output would be '$monkey' (i.e. all text up to END is treated as normal text, a开发者_如何学JAVAnd not parsed)
I want to avoid escaping or modify any of the text up until the END. is that possible?
e.g. ideally I want to do something like this
echo '
loads of lines here
';
In PHP 5.3, you can use nowdoc:
$var = <<<'END'
$monkey
END;
Otherwise, you'll always to worry about escaping something (all the escape codes and the dollar sign on heredoc, the same plus double quotes on double quote strings and backslashes and single codes in single quoted strings).
Even with heredoc or nowdoc, you would still have a problem if you have a literal END;
in the text you want to display. The only foolproof way is to put your literal text in a separate file, read it into a variable (with e.g. file_get_contents
), and then echo that variable.
精彩评论