Jump to content

censoring comments


ohdang888

Recommended Posts

When you run that, you'll notice that in certain situations.... like harrassment it might become harr****mess.

 

You could always just do ' word ' instead of 'word' though.....  Oh....  Then you could have problems with 'ass.' or 'ass!' for example.... hmmm....

 

 

Edit:

 

You could use regular expression word boundries I guess......

 


<?php

$str = "ass harrass.";

$bad = array('ass');

foreach($bad as $k => $word) {
$bad[$k] = '/\b' . $word . '\b/';
}

echo preg_replace($bad, '****', $str);
//**** harrass

?>

Link to comment
Share on other sites

<?php

$str = <<<H
This is a sentence with ass in it.
This is with ass at the end ass.
'ass'
"ass"
"Ass"
!ass!
ass
harrass
ass/ass
ASS
AsS
aSS
H;

$bad = array('ass');

foreach($bad as $k => $word) {
$bad[$k] = '/\b' . $word . '\b/i';
}

echo preg_replace($bad, '****', $str);

?>

 

 

Output:

 

This is a sentence with **** in it.

This is with **** at the end ****.

'****'

"****"

"****"

!****!

****

harrass

****/****

****

****

****

 

Regular expression word boundries....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.