phpheredocnowdoc

Php nowdoc (heredoc without parsing) is interpreting HTML Markup Characters - Not Desireable


I have PHP that looks like this:

$func_code = <<<'EOT'
foo1
foo2 '<foo3>'. foo4 . '</div>';
EOT;

echo $func_code;

And the output looks like this:

one_half   
foo1 foo2 ''. foo4 . '';
foo1 foo2 ''. foo4 . '';

As you can see, and are both completely removed. PHP docs claim that nowdoc won't parse anything inside the text block, but its obviously parsing the < and > symbols.

Anyone got an idea how to solve this?


Solution

  • It isn't PHP who's parsing it. It's your browser. Check the page's source.

    If you want the browser not to interpret these, send a Content-type header beforehand:

    header('Content-type: text/plain'); //This should be placed before any output is sent!