How to replace bad/abusive/swear/curse words through php ??

Description:- Hello guys today’s lesson is only for 18+ public because I really don’t want children to learn abusive words on my blog.
Today I’m going to show you how to replace abusive words through php like if someone typed in FUCK it will display like F**K .

<?php

$string = "Hello asshole I heared that you are asslicker too. Fuck off jerk and never show me your buttface.";
$swearWords = array("asshole","buttface","asslicker","jerk","fuck");
$replacer = array("a**hole","b**tface","a**li***r","j**k","f**k");
$filter = str_ireplace($swearWords,$replacer, $string);

echo $filter;
?>

*Note:- You can also use str_replace() but hence str_replace is case sensitive and str_ireplace() is not a case sensitive so it will accept both types of words lowercase or uppercase words.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s