【发布时间】:2017-05-27 13:58:48
【问题描述】:
我已经检查过了,它对我不起作用! PHP Write a variable to a txt file
这是我的代码,请看一下!我想将变量的所有内容写入文件。但是当我运行代码时,它只写了内容的最后一行!
<?php
$re = '/<li><a href="(.*?)"/';
$str = '
<li><a href="http://www.example.org/1.html"</a></li>
<li><a href="http://www.example.org/2.html"</a></li>
<li><a href="http://www.example.org/3.html"</a></li> ';
preg_match_all($re, $str, $matches);
echo '<div id="pin" style="float:center"><textarea class="text" cols="110" rows="50">';
// Print the entire match result
foreach($matches[1] as $content)
echo $content."\r\n";
$file = fopen("1.txt","w+");
echo fwrite($file,$content);
fclose($file);
?>
当我打开 1.txt 时,它只显示给我
应该是
http://www.example.org/1.html
http://www.example.org/2.html
http://www.example.org/3.html
我做错什么了吗?
【问题讨论】: