使用fopen()创建.php文件

使用fopen()创建.php文件,php,Php,我正在尝试这个: <a href=" <?php $fl= $p['n'].".php"; $fh = fopen($fl, 'w') or die("Can't create file"); if($fh) { $code =" <?php // html and php combined code (the php is for sessions) ?>"; echo fwrite($file,$code); fclose($file); }?>"&

我正在尝试这个:

<a href="
<?php
$fl= $p['n'].".php";
$fh = fopen($fl, 'w') or die("Can't create file");
if($fh)
{
$code ="
<?php
// html and php combined code (the php is for sessions)
?>";
echo fwrite($file,$code); 
    fclose($file); 
}?>"></a>

问题是,
$code
中的代码正在求值,我需要
$code
将代码像字符串一样保存。

使用
“$foo”
将求值,但
“$foo”
不会求值

但是,这会带来巨大的安全风险,因此我可能会备份并查看您正在尝试执行的操作。

使用功能(强调我的):

Nowdocs是单引号字符串,就像heredocs是双引号字符串。nowdoc的指定方式类似于herdoc,但在nowdoc内部不进行解析该结构非常适合嵌入PHP代码或其他大文本块,而无需转义

例子
您可能需要引用该文件名。
Example of string
spanning multiple lines
using nowdoc syntax.
$test_var
<a href="
<?php
$fh = fopen($p['n'].'.php', 'w') or die("Can't create file");
if($fh)
{
$code = <<<'EOD'
<?php
// html and php combined code (the php is for sessions)
?>"
EOD;
echo fwrite($file,$code); 
fclose($file); 
}?>"></a>