PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Citizen
Forum Contributor
Posts: 300 Joined: Wed Jul 20, 2005 10:23 am
Post
by Citizen » Mon Aug 07, 2006 9:00 pm
I'm trying to make a banlist of words for a form.
Code: Select all
$findme1 = 'badword';
$pos1 = strpos($content, $findme1);
if ($pos2 !== false) {
echo "That word is not allowed.";
Is there a way to add multiple words instead of just one or do I have to repeat this code over and over again for each banned word?
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Mon Aug 07, 2006 9:08 pm
Is there a way to add multiple words instead of just one or do I have to repeat this code over and over again for each banned word?
No you don't, yes there is.
Citizen
Forum Contributor
Posts: 300 Joined: Wed Jul 20, 2005 10:23 am
Post
by Citizen » Mon Aug 07, 2006 9:13 pm
Any help as to how? I've been looking all over php.net and havent found anything on multiple entries.
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Mon Aug 07, 2006 9:24 pm
OK, I'll help out a bit more.
Code: Select all
$black = array('rectum', 'brother lucker', 'choad', 'pentration', 'microsoft');
foreach ($black as $test) {
if (strpos($content, $test)) {
echo 'Bad word, bad child';
break;
}
}
Err this does the same and is probably better, I know feyd would prefer this anyway
Code: Select all
$black = as above;
if (in_array($test, $black)) {
echo 'Bad word, bad child';
}