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

StackOverflow https://stackoverflow.com/questions/14171004

  •  13-01-2022
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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!
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top