Re: eregi help
| From: | Lars Torben Wilson | Date: | Thu, 17 Aug 2000 10:20:20 +0000 |
| Subject: | Re: eregi help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-12196@lists.php.net to get a copy of this message | ||
Kris Howl writes:
> I've made a link submitter to work on my site. So the users type in their
> site name and url, click submit and it gets added to the list.
>
> However, to prevent idiots from adding links to unpleasant
> content/pornography I've created a filter. It's a txt document with a bunch
> of words in it to disallow.
>
> The problem is this:
>
> $sitename = "xxx"
>
> That works fine. However, if someone uses:
>
> $sitename = "xxxforyou"
>
> It won't pick up the xxx part and disallow it. Is there a way to make sure
> it does pick up the "xxx" part? The code I'm using is:
>
> eregi ($sitename,$ono)
>
> $ono being the variable which stores the fgets of the text file with the
> words.
>
> To know how I can do this would be a great help, as I also have to block
> URLs that contain those words.
>
> Thanks in advance,
>
> Kris
<?php
error_reporting(E_ALL);
function is_safe($url, $banned) {
while (list($word) = each($banned)) {
if (strpos("X$url", $word)) {
return false;
}
}
return true;
}
$distasteful_words = array(
'taxes',
'britney',
'earwigs
);
$url = 'http://www.britneyforyou.com';
if (!is_safe($url, $distasteful_words)) {
echo "Bad<br>\n";
} else {
echo "OK<br>\n";
}
?>
Be careful what you screen out, though. False positives are *really*
easy to get.
Cheers,
Torben
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+