2014-07-18 28 views
-3

我試圖編寫一些內容,以便在php文件中編寫內容,並在我的$ content變量中使用Heredoc和nowdoc,但php標記似乎無法正常工作並仍然顯示。如何在字符串中編寫PHP語法

$content = <<< EOT 
<?php 
    include $_SERVER['DOCUMENT_ROOT'] . '/home/index2.php'; 
?> 
EOT; 

任何想法?

回答

4

嘗試使用Output buffering代替定界符:

ob_start(); 
include $_SERVER['DOCUMENT_ROOT'] . '/home/index2.php'; 
$content = ob_get_clean(); 

參考:

+0

bes解決方案,我知道\使用它,剛剛註釋和$) – user1954544

0

你可以這樣做:

$content = "<" . <<< EOT 
?php 
    include $_SERVER['DOCUMENT_ROOT'] . '/home/index2.php'; 
> 
EOT;