使用包含变量的PHP脚本编写PHP文件

时间:2014-09-15 05:38:14

标签: php file fwrite

我正在使用以下PHP代码编写PHP文件: 编写php文件的代码是:

** write.php **

<?php
$myfile = fopen("writePhp.php", "w") or die("Unable to open file!");
$txt = "<?php \n error_reporting(E_WARNING & ~E_NOTICE & ~E_DEPRECATED);\n ";
fwrite($myfile, $txt);
$txtnew = "'$CALENDAR_DISPLAY = 'true';' \n";
fwrite($myfile, $txtnew);
?>

我想要的确切输出是:

writePhp.php

<?php    
error_reporting(E_WARNING & ~E_NOTICE & ~E_DEPRECATED);
    $CALENDAR_DISPLAY = 'true';

然而,我在writePhp文件中获得的实际结果是:

<?php 
error_reporting(E_WARNING & ~E_NOTICE & ~E_DEPRECATED);
' = 'true';' 

当我执行write.php文件时,我收到通知:

  

注意:未定义的变量:第11行的/var/www/shellPhp/write.php中的CALENDAR_DISPLAY

我面临的具体问题是我的代码没有在文件中写VARIABLE。任何建议或帮助表示赞赏。

0 个答案:

没有答案