stopping bad words<

admin

Administrator
Staff member
Okay I want to stop people from using harsh language when the post something to a site I am working on, now I thought of something but I can't test it just yet so I was wondering if you guys could tell me if this would work


$bad_word = array (bad, words, here);
$search = strpos($bad_word, $_POST['query']);

if ($search === false) {

continue on with script
}

else {

tell them they used bad words
}



just wondering if an array would work with this??? all help is <!-- m --><a class="postlink" href="appreciatedhttp://uk2.php.net/manual/en/function.strpos.php">appreciatedhttp://uk2.php.net/manual/en ... strpos.php</a><!-- m -->

int strpos ( string haystack, string needle [, int offset])

I'm afraid that your script won't work... but:


$bad_words = array('bad', 'words', 'here');

$used_bad = false;

for ($i = 0; $i < sizeof($bad_words); $i++)
{
$search = strpos($bad_words[$i], $_POST['query']);

if ($search !== false)
{
$used_bad = true;
break;
}
}

if ($used_bad == true)
{
echo "Naughty Naughty!";
}
else
{
// do whatever....
}or you can use array_search() or you can store the bad words in a file and open it then search, still an array so to speak.Thanks HK i will try that out when i get home... also going to have a look at array_search and see what i come up withokay witht that code it still works not sure why it isn't working well ill give you all of my code it always comes up as naughty naughty


<?php
error_reporting(E_ALL^E_NOTICE);
//declare values
$value = "http://";
$name = $_POST['website'];
$link = $_POST['web_name'];
$pos = strpos($name, $value);
$bad_words = array('bad', 'words', 'here');
//sets used_bad to false
$used_bad = false;

for ($i = 0; $i < sizeof($bad_words); $i++)
{
//searches for bad words in the string
$search = strpos($name, $bad_words[$i] );
//if bad words found set used bad to true
if ($search !== false)
{
$used_bad = true;
break;
}
}
//what happens when bad words used
if ($used_bad == true)
{
echo "Naughty Naughty!";
}
//looking for http:// in the string
else
{
if ($pos === false) {
echo "error msg";

}
//checking the company name is set
else {

if (isset($link) && $link) {
//writes link to the file
$fp = fopen ("affiliates.html" , "a+");
fwrite ($fp , "<a href=http://www.htmlforums.com/archive/index.php/\"$name\">$link</a><br />\r\n");
fclose ($fp);


echo "thank you msg";
}
else {
echo "error msg 2";
}
}
}
?>if ($used_bad == true)

that is wrong,

if ($used_bad)

if you set a variable to true then that variable is set to 1, false is 0.thanks scoutt appreciate your help also a big thanks to HK
 
Back
Top