Nowdoc in PHP vs PHP closing tag

From WikiVS, the open comparison website
Jump to: navigation, search

"Nowdoc" and PHP closing tag both allow you to output text while performing no PHP parsing. Either can be used to output HTML and Javascript to a web page.

[edit] PHP Closing Tag

For example, within a php script, you can put a closing tag, ?>, and everything after it will be treated as output (usually sent to a user's web browser, and displayed on their screen) rather than parsed as PHP code.


[edit] Nowdoc

Nowdoc syntax looks like this:

echo <<<'EOD' 
Here is some stuff that is not getting parsed as php code.
EOD;

The example above, using echo, imitates the php closing tag because the text that php is NOT interpreting is treated as output.

The useful thing about nowdoc is, you can also put the information into a variable:

$myVariable = <<<'EOD'
More stuff, not getting parsed as php code.
EOD;

You can then put that variable into a database, evaluate it later as php code, alter it, and / or treat it as output (echo)

See Also the Following Articles

Personal tools
Namespaces
Variants
Actions
Navigation
Ads
Toolbox