Hightlight or Censor Words in PHP
Hightlight or Censor Words in PHP
This tutorial will show you how to load a flat file and parse text to highlight or even censor out a word.
First step is to create an empty folder and create two text files. The first one rename it to badwords.txt, and the second as index.php
Open the badwords.txt file and enter in:
dog
fleas
Next open the index.php file, and past the following information
fopen("badwords.txt","r"); //Open the file that contains the words while($word = fgets($fh,4096)) { $message = ereg_replace(trim($word),"<b>$word</b>",$message); //replace words } return $message; //return censored words } echo censor($message); ?> |
Access the index.php through your localhost address, or web page, abd you should see the following:
My dog has fleas….
About the author
Written by Darren W..
Darren Hedlund is a freelance Web developer, writer, and data analyst. Darren has a degree in Computer Information Science and has spent the last 15 years developing application and environments from hand held, windows, web, virtual science, gaming, artificial intelligence and graphics design.
Darren's coding knowledge ranges from C+, Visual Basic, .NET, PHP, JSP, REXX, KIXX, and many others. His graphical and environmental knowledge stems in Macromedia Flash, 3D studio Max, Curious Labs Poser, Adobe Photoshop, and many others. Darren works in many platforms ranging from database, visual design, and, system development.
If you found this post useful you may also want to check these out:
- Making a JavaScript Tree Menuing System
- Perl binding, or vs. ||
- How to Make a Drop Down Template Theme Selector with PHP
- How to make a Hit Counter with PHP
- Setting Up Apache, PHP & MySQL On Windows
- Using Sessions to Make a PHP Login Script