[英]Create .php files with fopen()
I'm trying this: 我正在尝试这个:
<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>
The problem is that the codes inside $code
are being evaluated and I need that $code
simply save the codes like a string. 问题是
$code
正在被评估,我需要$code
只是像字符串一样保存代码。
Use PHP's nowdoc feature (emphasis mine): 使用PHP的nowdoc功能(强调我的):
Nowdocs are to single-quoted strings what heredocs are to double-quoted strings.
Nowdocs是单引号字符串,heredocs是双引号字符串。 A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc.
类似于heredoc指定了nowdoc,但是在nowdoc内部没有进行解析。 The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping .
该构造非常适合嵌入PHP代码或其他大块文本而无需转义 。
<?php
$test_var = 1;
$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
$test_var
EOD;
echo $str;
Outputs 输出
Example of string
spanning multiple lines
using nowdoc syntax.
$test_var
So this ... 所以这 ...
<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>
... should work for you. ......应该适合你。
Using "$foo"
will evaluate, but '$foo'
will not. 使用
"$foo"
会评估,但'$foo'
不会。
However, this is opens massive security risks so I would probably back up and take a look at what you're trying to do. 但是,这会带来巨大的安全风险,所以我可能会备份并查看您要做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.