php - How to read from text file until string is found and delete text until next specific string is found? -
my text file is:
;=-= title1-id1 =-=; zzzzzzzzzzzz xzqwnqrj90x9 n9ndfpo-f,m129 mf20fmf2-m, ;=-= end-title1-id1 =-=; ;=-= title2-id2 =-=; zzzzzzzzzzzz xzqwnqrj90x9 n9ndfpo-f,m129 mf20fmf2-m, ;=-= end-title2-id2 =-=;
i need read file , remove content want, example: ;=-= title2-id2 =-=;
until ;=-= end-title2-id2 =-=;
what's target? , ask have other solution achieve it. way, using files isn't proper way, if ask me & don't have many options. in file can search part of file content , after submit, searching result removed.
<form action="" method="post"> <input type="text" name="search"> <input type="submit" name="searching"> <p> example= insert "zzzzzzzzzzzz" </p> </form> <?php if(isset($_post['searching'])) { $file = 'test.txt'; $searchfor = $_post['search']; $contents = file_get_contents($file); $pattern = preg_quote($searchfor, '/'); $pattern = "/^.*$pattern.*\$/m"; if(preg_match_all($pattern, $contents, $matches)) { $action = str_replace($searchfor, '', $contents); file_put_contents($file, $action); } }
Comments
Post a Comment