note 54076 added to function.ucfirst

From: Date: Thu, 23 Jun 2005 07:48:44 +0000
Subject: note 54076 added to function.ucfirst
Groups: php.notes 
Request: Send a blank email to php-notes+get-90818@lists.php.net to get a copy of this message
This is a simple code to get all the 'bad words', stored in a database, out of the text. You could use str_ireplace but since that's installed on PHP5 only, this works as well. It strtolowers the text first then places capitals with ucfirst() where it thinks a capital should be placed, at a new sentence. The previous sentence is ended by '. ' then. <?php function filter($text){ $filters=mysql_query("SELECT word,result FROM filter"); while($filter=mysql_fetch_array($filters)){ $text=str_replace($filter[word],$filter[result],strtolower($text)); $parts=explode(". ",$text); for($i=0;$i<count($parts);$i++){ $parts[$i]=ucfirst($parts[$i]); } $text=implode(". ",$parts); } return $text; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.ucfirst.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54076 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54076&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54076&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54076&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54076&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54076&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54076&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54076&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90818) next »