Jump to content

how do i remove a certain word/phrase from a file ?


Recommended Posts

<?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.

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  :shrug:.

 

EDIT:

>file

My bad.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.