Re: Q: Logical assignment with strstr( )
| From: | Richard Lynch | Date: | Fri, 23 Feb 2007 20:31:59 +0000 |
| Subject: | Re: Q: Logical assignment with strstr( ) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-249317@lists.php.net to get a copy of this message | ||
On Fri, February 23, 2007 5:24 am, rgx@gmx.de wrote:
> strstr returns a string (in case the needle is found),
> but a boolean if there is no needle in the haystack.
As the manual suggests, using the === operator to check for FALSE is
probably the best way.
> I am trying to make a readable evaluation of some tests, but this
> fails
> to work as supposed because of
> - undefined results when "OR"ing strings with possible string (?)
> - use of bitwise OR operator ("|") where I am uncertain if I can
> write anything like $a ||= $b;
>
> Please read this snippet and tell me your ideas ;)
> Thanks
> Ralf
>
> $oLen = strlen ($commentary);
> $isSpam = ! strstr($_POST['Name']," ");
> $isSpam |= strlen
> (str_replace("http://","",$commentary)) <
> $oLen;
> $isSpam |= strstr($_POST['Name'],"@");
> $isSpam |= stristr($_POST['Name'],"Casino");
Using |= directly on these things is probably going to get ugly
quickly, as you will probably need something more like:
$isSpam |= (strstr($_POST['Name'],'@')===false ? 1:0);
Stepping back from the minutae of coding style...
Writing your own spam filter is probably a Bad Idea, as re-inventing
this particular wheel is far more effort than you have yet realized,
and PHP is almost certainly the wrong weapon in the first place...
I say this, having attempted to do it myself. :-)
Install Spam Assassin or something similar, and get way better results.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?