0
Failed to replace into text file.find string > read the whole line > replace. please help.
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="#" method="post"> <input type="text" name="xxx"> <br> <input type="submit" name="SubmitButton"> </form> </body> </html> <?php if(isset($_POST['SubmitButton'])){ $search = $_POST["xxx"]; $lines = file('file.txt'); foreach($lines as $line){ if(strpos($line, $search) !== false){ echo $line; $database = "file.txt"; $str = file_get_contents($database); $str = preg_replace("/.*\b" . $line . "\b.*\n/ui", "********\n", $str); $fp = fopen($database,'w'); fwrite($fp,$str); fclose($fp); } } } ?>
1 Respuesta
0
Try 'w+' on the fopen 2nd argument