![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Hi, I've created a small guestbook in PHP, now everything works fine except my badword filter. This is the code I use: $dirty_words = file("dirty_words.txt"); for ($word_count = 0; $word_count < count($dirty_words); $word_count++){ $message = str_replace($dirty_words, "****", $guestbook[3]); } This doesn't do anything! Can somebody please help me? Thanks, Maarten | |||
| Advertisements |
| | #2 | ||
| What are you doing with $message? Should be: $guestbook[3] = str_replace($dirty_words, "****", $guestbook[3]); "Maarten Hendrikx" <maarten.hendrikx@skynet.nospam.be> wrote in message news:3f438d89$0$777$ba620e4c@reader1.news.skynet.b e... > Hi, > > I've created a small guestbook in PHP, now everything works fine except my > badword filter. > This is the code I use: > $dirty_words = file("dirty_words.txt"); > > for ($word_count = 0; $word_count < count($dirty_words); $word_count++){ > $message = str_replace($dirty_words, "****", $guestbook[3]); > } > > This doesn't do anything! Can somebody please help me? > > Thanks, > Maarten > > > | |||
| | #3 | ||
| $message is just the name a give to the variable after the bad words have been stripped. I know that that isn't the problem... But what is? Help... Maarten | |||
| | #4 | ||
| Jason <jsumner1@cfl.rr.com> wrote: > Here's a better way to do it IMHO: > $dirty_words = file("dirty_words.txt"); > $message = $guestbook[3]; > foreach ($dirty_words as $word){ > $message = str_replace($word, "****", $message); > } > > echo $message; ..................................... Do you have a script for this? Not sure what guestbook[3] is. I thought you would need a file pointer to open the .txt file like a call to fopen("dirty_words.txt"). Or is it possible to use the following: .................. $badword=array("badword1","badword2","badword3"); foreach($badword as $word) { $message=str_replace()$badword,"*****",$message); } echo $message; ................ Please advise. Many thanks for your assistance. Tony Ritter | |||
| | #5 | ||
| Hi, The guestbook[3] is just the message part of my guestbook which I get from a txt-file. This is the code I now use and it works: // Filter out the dirty words $dirty_words = array('dirty', 'dirty'); foreach ($dirty_words as $word){ $guestbook[3] = eregi_replace($word, "", $guestbook[3]); } But now I want to be able to read the dirty words from an array in my script but from a txt-file which is easier to update. But It doesn't seem to work! Maarten | |||
| | #6 | ||
| I actually ran the script and found out why you were having problems. There were some trailing characters that you need to trim in order for the match to work. I added a trim() and it works fine. $dirty_words = file("dirty_words.txt"); foreach ($dirty_words as $word){ $guestbook[3]= str_replace(trim($word), "****", $guestbook[3]); } "Maarten Hendrikx" <maarten.hendrikx@skynet.nospam.be> wrote in message news:3f44b013$0$301$ba620e4c@reader0.news.skynet.b e... > Hi, > > The guestbook[3] is just the message part of my guestbook which I get from a > txt-file. > This is the code I now use and it works: > // Filter out the dirty words > $dirty_words = array('dirty', 'dirty'); > foreach ($dirty_words as $word){ > $guestbook[3] = eregi_replace($word, "", $guestbook[3]); > } > But now I want to be able to read the dirty words from an array in my script > but from a txt-file which is easier to update. But It doesn't seem to work! > > Maarten > > > | |||
| Featured Websites | ||||
|
![]() |
| Tags: badword, filter, guestbook, problem |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Guestbook recommendations? | ©® | CSS | 1 | 07-01-2007 2:15 PM |
| Star Filter? | Tony H | Graphics in general | 2 | 06-11-2007 11:51 PM |
| New filter in Vizros Plug-ins | Vizros Plug-ins | Graphics in general | 1 | 06-11-2007 7:11 PM |
| Moving PHP MySQL Guestbook from one host to another | ©® | Database | 1 | 06-10-2007 12:20 AM |
| Need Assistance from HP Filter Experts... | d_assassin | Web Site Hosting | 1 | 08-04-2006 8:07 PM |
| Featured Websites | ||||
|