Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Hightlight or Censor Words in PHP

By Darren W. Hedlund
2005-06-20


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

<?php
$message = "My dog has fleas....";
censor($message);
function censor($message)
 { 
 $fh = 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....



Tutorial Pages:
» Hightlight or Censor Words in PHP


 | Bookmark
Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1

Ask A Question
characters left.