Re: Q: Logical assignment with strstr( )

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, February 23, 2007 5:24 am, rgx@xxxxxx 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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux