Home > Backend Development > PHP Tutorial > php生成文件

php生成文件

WBOY
Release: 2016-06-23 13:19:39
Original
1060 people have browsed it

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);
Copy after login



[/code]


回复讨论(解决方案)

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

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

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


Copy after login

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

难道你要的是这个?

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


效果如下:

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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template