我正在构建一个CMS,但我遇到了这个问题。我需要为每个页面编写一个简单的php文件,并且需要传递一个ID和include函数。这是我写文件的代码:
$filename=mysqli_fetch_array($query))['pagename'];
$fw=fopen("../".$filename,'w',true);
fwrite( "<php
'$id = $id;
include('admin/renderpage.php');
?>");
fclose($fw);
这就是结果,看起来就像我需要的,只是变量$id不是一个实际的变量,include函数也不起作用。
<php
$id = 2;
include('admin/renderpage.php');
?>
尝试:
$filename=mysqli_fetch_array($query))['pagename'];
$fw=fopen("../".$filename,'w',true);
fwrite( $fw, "<?php
'$id = $id;
include('admin/renderpage.php');
?>");
fclose($fw);
PHP打开标记是:<?php
而不是<php
。PHP标签