I have a very long javascript (so long that it's too long to escape manually every single problematic character) that I need to return from a method inside a class. Are there way to return (return not echo or print) safely this kind of code?
我需要从类中的方法返回一个非常长的javascript(这么长,以至于手动逃避每个有问题的字符)。有没有办法安全地返回(返回不回显或打印)这种代码?
Thank you very much
非常感谢你
1 个解决方案
#1
I think you're after HEREDOC syntax or output buffering:
我想你是在使用HEREDOC语法或输出缓冲:
$str = <<<EOD
function javascript() { alert("foo"); }
EOD;
// or
ob_start();
?>
function javascript() { alert("foo"); }
<?php
$str = ob_get_clean();
#1
I think you're after HEREDOC syntax or output buffering:
我想你是在使用HEREDOC语法或输出缓冲:
$str = <<<EOD
function javascript() { alert("foo"); }
EOD;
// or
ob_start();
?>
function javascript() { alert("foo"); }
<?php
$str = ob_get_clean();