Re: [PHP] Question on explode and join.

2006-09-15 Thread Google Kreme


On 13 Sep 2006, at 11:02 , Dave Goodchild wrote:


$_SESSION['profane'] = false;

   foreach ($_POST as $value) {
   foreach ($swearbox as $profanity) {
   if (preg_match(/$profanity/i, $value)) {
   $errors = true;
   $_SESSION['profane'] = true;
   mail(TECHEMAIL, 'profane content attack attempt on  
DJST', From:
{$_SERVER['REMOTE_ADDRESS']} Time:  . date('d F Y G:i:s', time()- 
TIMEDIFF),

'[EMAIL PROTECTED]');
   }
   }
   }


wouldn't that trigger on assassination1 is ass was in $swearbox?

1 twice

--
Do not meddle in the affairs of Dragons for you are crunchy and taste  
good with ketchup


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



Re: [PHP] Question on explode and join.

2006-09-15 Thread Richard Lynch

$clean = $input;
foreach($badwords as $badword){
  $clean = preg_replace('/(\\W)$badword(\\W)/ims', '\\1' .
str_repeat('*', strlen($badword)) . '\\2', $clean);
}

On Wed, September 13, 2006 11:51 am, Beauford wrote:
 Hi,

 I have a form which I want to check for inappropriate words before it
 is
 posted. I have used explode to put the string into an array using a
 space as
 the delimiter and then I check it against another array that contains
 the
 inappropriate words.
 I then replace the inappropriate words with *'s and join the array
 back into
 a string.

 This works perfectly except for one thing.

 If the word in the string has a any kind of punctuation after it
 (period,
 comma) it won't be matched.

 So if  moron is an inappropriate word then you are a moron works,
 but you
 are a moron. won't.

 Any ideas?

 Thanks

 This is my code.

 function badwords($string) {

   $language = array(contains the inappropriate words);

   $words = explode( ,$string);
   $count = count(explode( , $string));

   for($i = 0; $i  $count; $i++) {
   if(in_array(strtolower($words[$i]), $language)) {
   $words[$i] = *;
   }
   }

   $newcomments = join( ,$words);

   return $newcomments;
 }



-- 
Like Music?
http://l-i-e.com/artists.htm

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



RE: [PHP] Question on explode and join.

2006-09-14 Thread tedd

At 5:55 PM -0400 9/13/06, Beauford wrote:


The problem with scripts like these is there is so many variables to deal
with. First, this doesn't deal with uppercase. So a word like bAdWoRd would
not get detected, or a word beginning a sentence. Also, a word within a word
like wordbadwordword would not be detected, and I'm sure there are more I
haven't discovered yet. I haven't had much time to play around with it since
earlier today, so I haven't experimented with it, but ideas are welcome.



The problem of wordbadwordword is not solvable unless you have a 
dictionary of acceptable words as well. For example, words like 
assumption and hellacious would be problematic.


Furthermore, there are words that are perfectly acceptable, but their 
meanings differ in context, like screw. So you would need a context 
checker, which presents its own problems.


tedd




Thanks

-Original Message-
From: Ducarom [mailto:[EMAIL PROTECTED]
Sent: September 13, 2006 2:26 PM
To: Beauford
Cc: php
Subject: Re: [PHP] Question on explode and join.

I made some changes to the script from Butera. Now it only replaces complete
words.

$dirty = array(
   'ipsum',
   'eloquentiam',
   'Vero'
);

foreach ($dirty as $key = $word) {
$dirty[$key] = '/\b'. $word . '\b/'; }

$string = Lorem ipsum ius no etiam veniam, usu alii novum ne, sed cu
molestiae eloquentiam. Vero invenire philosophia est ne, quo nemore timeam
an.;

$clean = preg_replace($dirty, '*', $string);

echo brstring: . $string;
echo brclean: . $clean;

On 9/13/06, Beauford [EMAIL PROTECTED] wrote:


 There ya go. Works and is shorter than what I did. Thanks.

 One other question. if I have bunny and bunnyhole in the badword
 array. if someone types in bunnyhole, I end up getting *hole in the
 clean string. If I change the order of the words in the array would
 that solve the problem?

 Thanks



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



--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Question on explode and join.

2006-09-14 Thread Ray Hauge
On Wednesday 13 September 2006 11:51, Beauford wrote:
 Hi,

 I have a form which I want to check for inappropriate words before it is
 posted. I have used explode to put the string into an array using a space
 as the delimiter and then I check it against another array that contains
 the inappropriate words.
 I then replace the inappropriate words with *'s and join the array back
 into a string.

 This works perfectly except for one thing.

 If the word in the string has a any kind of punctuation after it (period,
 comma) it won't be matched.

 So if  moron is an inappropriate word then you are a moron works, but
 you are a moron. won't.

 Any ideas?

 Thanks

 This is my code.

 function badwords($string) {

   $language = array(contains the inappropriate words);

   $words = explode( ,$string);
   $count = count(explode( , $string));

   for($i = 0; $i  $count; $i++) {
   if(in_array(strtolower($words[$i]), $language)) {
   $words[$i] = *;
   }
   }

   $newcomments = join( ,$words);

   return $newcomments;
 }

This website answered a lot of my questions about the same situation.  I 
tested it on my development environment, and it worked just fine.

http://www.php-mag.net/magphpde/magphpde_article/psecom,id,637,nodeid,21.html

-- 
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

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



Re: [PHP] Question on explode and join.

2006-09-14 Thread Ray Hauge
On Thursday 14 September 2006 09:47, Ray Hauge wrote:
 On Wednesday 13 September 2006 11:51, Beauford wrote:
  Hi,
 
  I have a form which I want to check for inappropriate words before it is
  posted. I have used explode to put the string into an array using a space
  as the delimiter and then I check it against another array that contains
  the inappropriate words.
  I then replace the inappropriate words with *'s and join the array back
  into a string.
 
  This works perfectly except for one thing.
 
  If the word in the string has a any kind of punctuation after it (period,
  comma) it won't be matched.
 
  So if  moron is an inappropriate word then you are a moron works, but
  you are a moron. won't.
 
  Any ideas?
 
  Thanks
 
  This is my code.
 
  function badwords($string) {
 
  $language = array(contains the inappropriate words);
 
  $words = explode( ,$string);
  $count = count(explode( , $string));
 
  for($i = 0; $i  $count; $i++) {
  if(in_array(strtolower($words[$i]), $language)) {
  $words[$i] = *;
  }
  }
 
  $newcomments = join( ,$words);
 
  return $newcomments;
  }

 This website answered a lot of my questions about the same situation.  I
 tested it on my development environment, and it worked just fine.

 http://www.php-mag.net/magphpde/magphpde_article/psecom,id,637,nodeid,21.ht
ml

 --
 Ray Hauge
 Programmer/Systems Administrator
 American Student Loan Services
 www.americanstudentloan.com
 1.800.575.1099

I didn't recognize this until after I sent the email, but the article was 
written by Chris Shiflett, so I thought I'd give him credit.  Excellent as 
always :)

-- 
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

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



RE: [PHP] Question on explode and join.

2006-09-14 Thread Beauford
I read your email, but I'm not using sessions and not really planning too.
But some of your code may be able to be modified to do what I need.

Thanks for the input.

B


  _  

From: Dave Goodchild [mailto:[EMAIL PROTECTED] 
Sent: September 14, 2006 8:52 AM
To: Beauford
Subject: Re: [PHP] Question on explode and join.


Hi. If you re-read my reponse you will see that it uses preg_replace with
the i flag which ignores case and will match banned words within words. With
a little modification (I can help if you like) you can easily use it in your
case. 


Re: [PHP] Question on explode and join.

2006-09-13 Thread Dave Goodchild

Hi. I have just added a profanity filter to a current project which runs
like so (all form values are passed into the session after checking for
required fields etc). $swearbox is an array containing profanities so I
won't include it here!

$_SESSION['profane'] = false;

   foreach ($_POST as $value) {
   foreach ($swearbox as $profanity) {
   if (preg_match(/$profanity/i, $value)) {
   $errors = true;
   $_SESSION['profane'] = true;
   mail(TECHEMAIL, 'profane content attack attempt on DJST', From:
{$_SERVER['REMOTE_ADDRESS']} Time:  . date('d F Y G:i:s', time()-TIMEDIFF),
'[EMAIL PROTECTED]');
   }
   }
   }

...if $errors is true at the end of processing I send the user back to the
form. In this instance if there are rude words $_SESSION['profane'] is set
and we warn the user.







--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk


Re: [PHP] Question on explode and join.

2006-09-13 Thread Eric Butera

On 9/13/06, Beauford [EMAIL PROTECTED] wrote:


Hi,

I have a form which I want to check for inappropriate words before it is
posted. I have used explode to put the string into an array using a space
as
the delimiter and then I check it against another array that contains the
inappropriate words.
I then replace the inappropriate words with *'s and join the array back
into
a string.

This works perfectly except for one thing.

If the word in the string has a any kind of punctuation after it (period,
comma) it won't be matched.

So if  moron is an inappropriate word then you are a moron works, but
you
are a moron. won't.

Any ideas?

Thanks

This is my code.

function badwords($string) {

$language = array(contains the inappropriate words);

$words = explode( ,$string);
$count = count(explode( , $string));

for($i = 0; $i  $count; $i++) {
if(in_array(strtolower($words[$i]), $language)) {
$words[$i] = *;
}
}

$newcomments = join( ,$words);

return $newcomments;
}




Perhaps you could try an approach like this:
?php
$dirty = array(
   'ipsum',
   'eloquentiam',
   'Vero'
);

$string = Lorem ipsum ius no etiam veniam, usu alii novum ne, sed cu
molestiae eloquentiam. Vero invenire philosophia est ne, quo nemore timeam
an.;

$clean = str_replace($dirty, '*', $string);

echo brstring: . $string;
echo brclean: . $clean;

GENERATES:

string: Lorem ipsum ius no etiam veniam, usu alii novum ne, sed cu molestiae
eloquentiam. Vero invenire philosophia est ne, quo nemore timeam an.
clean: Lorem * ius no etiam veniam, usu alii novum ne, sed cu molestiae *. *
invenire philosophia est ne, quo nemore timeam an.


Re: [PHP] Question on explode and join.

2006-09-13 Thread Christopher Watson

Definitely look into preg_match or even preg_replace, instead of
tokenizing the string and rubbing it up against an array of your own.
Iterate on your array of bad words, and then use Regular Expressions
to selectively hunt and squash.  You MAY be able to do it in one regex
operation by building a search pattern that covers everything.  Don't
know how much the PCRE functions can swallow at once, but it's worth a
try.

Christopher Watson
Principal Architect
The International Variable Star Index (VSX)
http://vsx.aavso.org


On 9/13/06, Beauford [EMAIL PROTECTED] wrote:

Hi,

I have a form which I want to check for inappropriate words before it is
posted. I have used explode to put the string into an array using a space as
the delimiter and then I check it against another array that contains the
inappropriate words.
I then replace the inappropriate words with *'s and join the array back into
a string.

This works perfectly except for one thing.

If the word in the string has a any kind of punctuation after it (period,
comma) it won't be matched.

So if  moron is an inappropriate word then you are a moron works, but you
are a moron. won't.

Any ideas?

Thanks

This is my code.

function badwords($string) {

   $language = array(contains the inappropriate words);

   $words = explode( ,$string);
   $count = count(explode( , $string));

   for($i = 0; $i  $count; $i++) {
   if(in_array(strtolower($words[$i]), $language)) {
   $words[$i] = *;
   }
   }

   $newcomments = join( ,$words);

   return $newcomments;
}




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



RE: [PHP] Question on explode and join.

2006-09-13 Thread Beauford
There ya go. Works and is shorter than what I did. Thanks.
 
One other question. if I have bunny and bunnyhole in the badword array. if
someone types in bunnyhole, I end up getting *hole in the clean string. If I
change the order of the words in the array would that solve the problem?
 
Thanks

  _  

From: Eric Butera [mailto:[EMAIL PROTECTED] 
Sent: September 13, 2006 1:07 PM
To: Beauford
Cc: php
Subject: Re: [PHP] Question on explode and join.


On 9/13/06, Beauford [EMAIL PROTECTED] wrote: 

Hi,

I have a form which I want to check for inappropriate words before it is
posted. I have used explode to put the string into an array using a space as
the delimiter and then I check it against another array that contains the 
inappropriate words.
I then replace the inappropriate words with *'s and join the array back into
a string.

This works perfectly except for one thing.

If the word in the string has a any kind of punctuation after it (period, 
comma) it won't be matched.

So if  moron is an inappropriate word then you are a moron works, but you
are a moron. won't.

Any ideas?

Thanks

This is my code.

function badwords($string) {

$language = array(contains the inappropriate words);

$words = explode( ,$string);
$count = count(explode( , $string));

for($i = 0; $i  $count; $i++) { 
if(in_array(strtolower($words[$i]), $language)) {
$words[$i] = *;
}
}

$newcomments = join( ,$words);

return $newcomments;
}



Perhaps you could try an approach like this:
?php
$dirty = array(
'ipsum',
'eloquentiam',
'Vero'
);

$string = Lorem ipsum ius no etiam veniam, usu alii novum ne, sed cu
molestiae eloquentiam. Vero invenire philosophia est ne, quo nemore timeam
an.; 

$clean = str_replace($dirty, '*', $string);

echo brstring: . $string;
echo brclean: . $clean; 


GENERATES:

string: Lorem ipsum ius no etiam veniam, usu alii novum ne, sed cu molestiae
eloquentiam. Vero invenire philosophia est ne, quo nemore timeam an.
clean: Lorem * ius no etiam veniam, usu alii novum ne, sed cu molestiae *. *
invenire philosophia est ne, quo nemore timeam an.




Re: [PHP] Question on explode and join.

2006-09-13 Thread Jon Anderson

Beauford wrote:

I have a form which I want to check for inappropriate words before it is
posted. I have used explode to put the string into an array using a space 
as

the delimiter and then I check it against another array that contains the
inappropriate words.
I then replace the inappropriate words with *'s and join the array back 
into

a string.

This works perfectly except for one thing.

If the word in the string has a any kind of punctuation after it (period,
comma) it won't be matched.

So if  moron is an inappropriate word then you are a moron works, but 
you

are a moron. won't.

Any ideas?


$filtered = 
str_ireplace(array('naughty','words'),array('*','*'),$_POST['input_string']);


jon 


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



Re: [PHP] Question on explode and join.

2006-09-13 Thread Ducarom

I made some changes to the script from Butera. Now it only replaces complete
words.

$dirty = array(
  'ipsum',
  'eloquentiam',
  'Vero'
);

foreach ($dirty as $key = $word) {
   $dirty[$key] = '/\b'. $word . '\b/';
}

$string = Lorem ipsum ius no etiam veniam, usu alii novum ne, sed cu
molestiae eloquentiam. Vero invenire philosophia est ne, quo nemore timeam
an.;

$clean = preg_replace($dirty, '*', $string);

echo brstring: . $string;
echo brclean: . $clean;

On 9/13/06, Beauford [EMAIL PROTECTED] wrote:


There ya go. Works and is shorter than what I did. Thanks.

One other question. if I have bunny and bunnyhole in the badword array. if
someone types in bunnyhole, I end up getting *hole in the clean string. If
I
change the order of the words in the array would that solve the problem?

Thanks



RE: [PHP] Question on explode and join.

2006-09-13 Thread Beauford
 
The problem with scripts like these is there is so many variables to deal
with. First, this doesn't deal with uppercase. So a word like bAdWoRd would
not get detected, or a word beginning a sentence. Also, a word within a word
like wordbadwordword would not be detected, and I'm sure there are more I
haven't discovered yet. I haven't had much time to play around with it since
earlier today, so I haven't experimented with it, but ideas are welcome.

Thanks

-Original Message-
From: Ducarom [mailto:[EMAIL PROTECTED] 
Sent: September 13, 2006 2:26 PM
To: Beauford
Cc: php
Subject: Re: [PHP] Question on explode and join.

I made some changes to the script from Butera. Now it only replaces complete
words.

$dirty = array(
   'ipsum',
   'eloquentiam',
   'Vero'
);

foreach ($dirty as $key = $word) {
$dirty[$key] = '/\b'. $word . '\b/'; }

$string = Lorem ipsum ius no etiam veniam, usu alii novum ne, sed cu
molestiae eloquentiam. Vero invenire philosophia est ne, quo nemore timeam
an.;

$clean = preg_replace($dirty, '*', $string);

echo brstring: . $string;
echo brclean: . $clean;

On 9/13/06, Beauford [EMAIL PROTECTED] wrote:

 There ya go. Works and is shorter than what I did. Thanks.

 One other question. if I have bunny and bunnyhole in the badword 
 array. if someone types in bunnyhole, I end up getting *hole in the 
 clean string. If I change the order of the words in the array would 
 that solve the problem?

 Thanks


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



Re: [PHP] Question on explode and join.

2006-09-13 Thread Ducarom

You can make it case insensitive by replacing:

$dirty[$key] = '/\b'. $word . '\b/'
with
$dirty[$key] = '/\b'. $word . '\b/i'

On 9/13/06, Beauford [EMAIL PROTECTED] wrote:



The problem with scripts like these is there is so many variables to deal
with. First, this doesn't deal with uppercase. So a word like bAdWoRd
would
not get detected, or a word beginning a sentence. Also, a word within a
word
like wordbadwordword would not be detected, and I'm sure there are more I
haven't discovered yet. I haven't had much time to play around with it
since
earlier today, so I haven't experimented with it, but ideas are welcome.

Thanks

-Original Message-
From: Ducarom [mailto:[EMAIL PROTECTED]
Sent: September 13, 2006 2:26 PM
To: Beauford
Cc: php
Subject: Re: [PHP] Question on explode and join.

I made some changes to the script from Butera. Now it only replaces
complete
words.

$dirty = array(
   'ipsum',
   'eloquentiam',
   'Vero'
);

foreach ($dirty as $key = $word) {
$dirty[$key] = '/\b'. $word . '\b/'; }

$string = Lorem ipsum ius no etiam veniam, usu alii novum ne, sed cu
molestiae eloquentiam. Vero invenire philosophia est ne, quo nemore timeam
an.;

$clean = preg_replace($dirty, '*', $string);

echo brstring: . $string;
echo brclean: . $clean;

On 9/13/06, Beauford [EMAIL PROTECTED] wrote:

 There ya go. Works and is shorter than what I did. Thanks.

 One other question. if I have bunny and bunnyhole in the badword
 array. if someone types in bunnyhole, I end up getting *hole in the
 clean string. If I change the order of the words in the array would
 that solve the problem?

 Thanks


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