php生成文件

WBOY
WBOYOriginal
2016-06-23 13:19:391055browse

a.php<?php$a="****";require_once dirname(__FILE__) . '/b.php';?>b.php<?php............echo $a;.......?>之后生成  xxx.txt  内容是 b.php里的内容这个功能要怎么实现?本来使用下面方法做的,但是写入的内容有 双引号和单引号[code=php]$myfile = fopen("protected/views/1/_form.php", "w") or die("Unable to open file!");$txt = "Bill Gates\n";fwrite($myfile, $txt);



[/code]


回复讨论(解决方案)

既然完全相同为什么不用程序copy一份呢

$s =<<< 'TXT'<?php............echo $a;.......?>TXT;file_put_contents('c.php', $s);

$data = file_get_contents('b.php');file_put_contents('c.php', $data, true);


   
生成的c.php
<?php............echo $a;    //变量a没有转义     这个用替换处理吗?.......?>

难道你要的是这个?

$data = file_get_contents('http://localhost/a.php');file_put_contents('xxx.txt', $data);


效果如下:

<?php$a=1;$s =<<< 'TXT'<?php....... $a;......?>TXT;

生成后的文件
<?php....... 1;......?>

$s =.......
 $a;
......
?>
TXT;
去掉 $s =

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn