NameSilo

[Resolved] Filtering profanity

Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
Namecheap AuctionsNamecheap Auctions
Watch

jido

VIP Member
Impact
61
Filtering profanity

Hello, I am looking for a good php solution to filter out swear words in existing text. The text needs to be displayed edited.

Do you know any?
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
If you are getting it out out a db, Make a function called profanityFilter($text) { } and then inside it, do a foreach($text as $value) { } and then get from a db like while($row=mysql_fetch_array($query)) { } and inside that do: str_ireplace($row['badword'], $row['replacewith'], $value); Then it will be done.. An example is shown below:
PHP:
<?php
// profanity filter
public function profanityFilter($text) {
$query = mysql_query("SELECT * FROM `wordfilter`")or die(mysql_error());
while($row = mysql_fetch_array($query)) {
str_ireplace($row['badword'], $row['replacewith'], $text);
}
}
?>

That may not be exactly right.. but it will get you on the right tracks.


Edit, Another way:
PHP:
<?php
function filter($text) {
$badwords = array('one' => '***', 'two' => '***', 'three' => '*****');
str_ireplace($badwords[0], $badwords[1], $text);}
}
?>

Second method doesn't use a db.. It's not as dynamic really..
If this helped you, Please leave rep, Thanks :)
 
Last edited:
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

A browser tab with a favicon next to the page title
Search members
You can now search for members by name, company, location and more. Open the search at the top of any page and choose Members. You will...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back