Reputation: 103
I want to write contents that display in the browser to a text file. I want to display the data both in browser and write to a text file. Here is my script. I used file_put_contents to write to text file. But I can't see any data when I access my text file.
<?php
$dfile = fopen("/usr/share/dict/words", "r");
while(!feof($dfile)) {
$mynextline = fgets($dfile);
if (preg_match("/lly/", $mynextline)) echo "$mynextline<br>";
}
$file = 'mycontent.txt'
file_put_contents($file, $mynextline);
?>
Upvotes: 0
Views: 343
Reputation: 890
I would code it something like this
<?php
$dfile = fopen("/usr/share/dict/words", "r");
$ob_file = fopen('mycontent.txt',"w");
while(!feof($dfile)) {
$mynextline = fgets($dfile);
if (preg_match("/lly/", $mynextline)) {
echo "$mynextline<br>";
fwrite($ob_file, $mynextline);
}
}
fclose($dfile);
fclose($ob_file);
?>
Upvotes: 1