A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Foul language filter in PHPYou will learn how to create a simple PHP foul language filter function which uses a file containing foul words to replace them in the string of your choice with asterisks. |
On Saturday, February 11th 2006 at 07:44 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 3.3 with 6 votes) |
|||
|
In this tutorial we will create a simple PHP function which will replace foul words with asterisks or any character or string of your choice. The list of foul words will be retrieved from a text file. Each foul word must be entered on a different line. A sample foul language file can be download at http://www.geekpedia.com/Scripts/foul.txt (reader's discretion is advised). Let's view the function. It's not too complicated and the comments should guide you through:
All you really need to do for this script to work, is to place the foul.txt file in the same directory, and to call the LangFilter() function on the string that you need filtered, like in the example below:
Indeed, if dirtbag would've been on the list, the following line would output: If ******* would have been a dirty word, it would be replaced now by asterisks. Here is the same function but without the comments, in case you want to copy and paste it in your code, and you're not interested in the comments.
|
||||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
||||
|
||||
Current CommentsHi,
When i run unlink($filepath) on localhost i am getting below error
Warning: unlink(E: Document (2).txt) [function.unlink]: Permission denied in C:\Inetpub\wwwroot\Mapmyoffer\main.php on line
Can you help me?
I'm not sure what that has to do with this tutorial, so you should ask in the forums next time.
Your problem is that the IIS user doesn't have permission to delete that path. You need to add the necessary permissions.
The tutorial is OK, but could be done more effeciently:
1) Using str_replace instead of eregi_replace.
2) Instead of looping and adding the stars, do $RepChar = str_repeat('*', strlen($FoulWord));
It doesn't work at all.
TO TEJAL:
chmod you directory to 0777
Good tutorial thanks
First, thank you for creating and sharing this script! It works absolutely fantastic!
Second, I configured the script a little differently and thought I would share it with everyone.
1. I placed the script in a folder called \"commonfiles\". This is where I keep all scripts I use on a variety of marketing-specific microsites.
2. I placed the following string of code inside my php-based form processing script:
if(!preg_match(\"/LangFilter()/\",$_POST[\"Company\"])) {die(\"<p align=\'center\'><font face=\'Arial\' size=\'3\' color=\'#000000\'>You have entered inappropriate language in one of the fields provided on this form. <br><br>You will need to click on your browsers \\\"Back\\\" button and correct this unacceptable entry in order to complete the submission process...</font></p>\");}
Cheers!
rsort($Foul);
So included words won't come before
Please forgive me but my background is in mainframes. Before i go down this road would this script possibly be able to filter language from video running via a PowerDVD application on the PC (xp windows)?
I prefer to just use a web service like <a href="http://www.webpurify.com">webpurify.com</a> to filter out foul language or profanity.
I'm taking the words from a database, instead of a file, however, it is only reading the first value. I've tried with a file and still the same thing.
Any ideas?
foreach($qry->result_array() as $word) {
$words[] = $word['word'];
}
foreach($words as $foulWord) {
$foulWord = trim($foulWord);
... etc
does it work on PC videogames (call of duty, Battlefield)
does it work on PC videogames (call of duty, Battlefield)
Related Tutorials
Related Source Code
PHP Job Search