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); } } } ?>

13th Mar 2023, 9:42 AM
Syafiq
Syafiq - avatar
1 Respuesta
0
Try 'w+' on the fopen 2nd argument
24th Mar 2023, 3:57 PM
William Mabotja
William Mabotja - avatar