簡體   English   中英

使用PHP fwrite編寫php文件

[英]Use PHP fwrite to write php file

我正在建立一個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標簽

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM