Re: [PHP] Replacing with f*ck and f*cking

2008-10-26 Thread Stan Vassilev | FM
My question is this, for just two words its fine to use the above, but a 
pal tells me that if using a lot of words (eg: 15) and the $comment is big 
then it can take quite some time and be a bit of a processing strain as 
well because php first checks the first word from the good list against 
all the 15 words in the bad list against the comment then moves to the 
second word etc.




You should do the filtering on save, not on display, this way the processing 
time will drop by order of few magnitudes in comparison.


Always save the original post content as well, in case you want to tweak the 
filter and reprocess the messages.


Regards, Stan Vassilev 



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



Re: [PHP] Replacing with f*ck and f*cking

2008-10-26 Thread Ashley Sheridan
On Sun, 2008-10-26 at 10:18 +0200, Stan Vassilev | FM wrote:
  My question is this, for just two words its fine to use the above, but a 
  pal tells me that if using a lot of words (eg: 15) and the $comment is big 
  then it can take quite some time and be a bit of a processing strain as 
  well because php first checks the first word from the good list against 
  all the 15 words in the bad list against the comment then moves to the 
  second word etc.
 
 
 You should do the filtering on save, not on display, this way the processing 
 time will drop by order of few magnitudes in comparison.
 
 Always save the original post content as well, in case you want to tweak the 
 filter and reprocess the messages.
 
 Regards, Stan Vassilev 
 
 
What you really need to watch out for is words which you're going to
censor which might be part of other names. Sex is an obvious one, as it
appeared in the borough name of my old address: Middlesex. Instead of
using str_replace, what about using preg_replace, which gives you a bit
more control over the words that you are replacing, for example, only
words on their own, etc. This will also let you get around deliberate
mis-spellings of a profanity, such as 'fcuk', by using an expression
like /f[uc]k/iw

Obviously, this list could get pretty comprehensive, so like Andrew
said, maybe you should look to see how some of the open source projects
do it.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Replacing with f*ck and f*cking

2008-10-26 Thread Larry Garfield
On Sunday 26 October 2008 5:06:09 am Ashley Sheridan wrote:

 Obviously, this list could get pretty comprehensive, so like Andrew
 said, maybe you should look to see how some of the open source projects
 do it.


 Ash
 www.ashleysheridan.co.uk

The way Drupal handles such filtering is simple caching.  As a policy we never 
filter general content on save, because we may want to change the filter 
format later and destroying user-submitted data is *not cool*.  However, we 
do apply a number of possible filters on display (add line breaks, convert 
URLs to clickable, do bad word filtering, or any number of other things) 
and then just cache the result.  The cache lookup (based on a hash of the 
string being filtered and the ID of the filter set to apply) is far faster 
than reapplying the filters every time.  We've found this mechanism to scale 
very well.

-- 
Larry Garfield
[EMAIL PROTECTED]

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



[PHP] Replacing with f*ck and f*cking

2008-10-25 Thread Ryan S
Hey!
I'm just trying to replace some of the more bad words with their slightly 
censored counterparts like so

$bad_words = array(/*Well you know the words so am not going to write them 
here*/);
$bad_words_replacements = array(f*ck, f*cking);
$comment = str_replace($bad_words,$bad_words_replacements,  $comment);

My question is this, for just two words its fine to use the above, but a pal 
tells me that if using a lot of words (eg: 15) and the $comment is big then it 
can take quite some time and be a bit of a processing strain as well because 
php first checks the first word from the good list against all the 15 words in 
the bad list against the comment then moves to the second word etc.

Is this really bad processing wise and would you recommend any other way of 
doing this?
The other question i have is, wont f*ck catch f*cking as well? so should i 
delete the longer f*cking?

I'm not really trying to stop people swearing... just trying to make it not 
jump out so much, this was the poster is happy coz i have not censored him to 
bits and the reader should be a bit happy coz its a bit decent.

Thanks!
R


  

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



Re: [PHP] Replacing with f*ck and f*cking

2008-10-25 Thread Andrew Barnett
Maybe you should look at the source code of an open source project that can
already do this such as phpBB.  I'm not exactly sure where to find it in the
phpBB code though.

Andrew


2008/10/26 Ryan S [EMAIL PROTECTED]

 Hey!
 I'm just trying to replace some of the more bad words with their slightly
 censored counterparts like so

 $bad_words = array(/*Well you know the words so am not going to write them
 here*/);
 $bad_words_replacements = array(f*ck, f*cking);
 $comment = str_replace($bad_words,$bad_words_replacements,  $comment);

 My question is this, for just two words its fine to use the above, but a
 pal tells me that if using a lot of words (eg: 15) and the $comment is big
 then it can take quite some time and be a bit of a processing strain as well
 because php first checks the first word from the good list against all the
 15 words in the bad list against the comment then moves to the second word
 etc.

 Is this really bad processing wise and would you recommend any other way of
 doing this?
 The other question i have is, wont f*ck catch f*cking as well? so
 should i delete the longer f*cking?

 I'm not really trying to stop people swearing... just trying to make it not
 jump out so much, this was the poster is happy coz i have not censored him
 to bits and the reader should be a bit happy coz its a bit decent.

 Thanks!
 R




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