我尝试写一些内容以便在php文件中写入,在我的$ content变量中我使用Heredoc和nowdoc但是php标签似乎无法正常工作并且仍然显示。
$content = <<< EOT
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/home/index2.php';
?>
EOT;
有什么想法吗?
答案 0 :(得分:4)
尝试使用Output buffering代替heredoc:
ob_start();
include $_SERVER['DOCUMENT_ROOT'] . '/home/index2.php';
$content = ob_get_clean();
参考:
答案 1 :(得分:0)
你可以这样做:
$content = "<" . <<< EOT
?php
include $_SERVER['DOCUMENT_ROOT'] . '/home/index2.php';
>
EOT;