yami007 Posted September 16, 2010 Share Posted September 16, 2010 for example, i want to search for an the string "example@example.com" and erase it. thanks in advance ! Quote Link to comment https://forums.phpfreaks.com/topic/213608-how-do-i-remove-a-certain-wordphrase-from-a-file/ Share on other sites More sharing options...
jcbones Posted September 17, 2010 Share Posted September 17, 2010 str_replace() <?php $str = 'I want you to go to example@example.com'; echo str_replace('example@example.com','',$str); ?> Quote Link to comment https://forums.phpfreaks.com/topic/213608-how-do-i-remove-a-certain-wordphrase-from-a-file/#findComment-1111916 Share on other sites More sharing options...
yami007 Posted September 17, 2010 Author Share Posted September 17, 2010 how do i do that in a text file like "emails.txt" ? is there a way to do that? thank you ! Quote Link to comment https://forums.phpfreaks.com/topic/213608-how-do-i-remove-a-certain-wordphrase-from-a-file/#findComment-1112148 Share on other sites More sharing options...
jcbones Posted September 17, 2010 Share Posted September 17, 2010 <?php $filename = 'emails.txt'; if(isset($_GET['r'])) { $file = file_get_contents($filename); $remove = strip_tags($_GET['r']); $content = str_replace($remove,'',$file); file_put_contents($filename,$content); } echo nl2br(file_get_contents($filename)); ?> <form action="" method="get"> <input type="text" name="r" value="" /> <input type="submit" name="submit" value=" Remove " /> </form> UN-Tested. Quote Link to comment https://forums.phpfreaks.com/topic/213608-how-do-i-remove-a-certain-wordphrase-from-a-file/#findComment-1112322 Share on other sites More sharing options...
Username: Posted September 18, 2010 Share Posted September 18, 2010 Another method that was posted by a user here is function wordsExist(&$string, $words) { foreach($words as &$word) { if(stripos($string, $word) !== false) { return true; } } return false; } $string = $VARIABLE; if (wordsExist($string, array('WORD1','WORD2'))) { die("<font color='red'><font size='15'><strong><center>Your post contains a blocked word!"); } I don't know the name of who posted it, so sorry . EDIT: >file My bad. Quote Link to comment https://forums.phpfreaks.com/topic/213608-how-do-i-remove-a-certain-wordphrase-from-a-file/#findComment-1112345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.