Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Php Word Filter, Have you accidently sworn on your site? Or do you want to keep visitor
KansukeKojima
post Nov 20 2007, 07:25 PM
Post #1


Privileged Member
*********

Group: [HOSTED]
Posts: 519
Joined: 13-October 06
From: Alberta, Canada
Member No.: 31,584



This is pretty simple but very useful if you don't want people to swear. We will be using str_replace for this.

CODE
<?php
str_replace ("curseword, "replacemet");
?>


Thats pretty simple, just fill in the curse word and the replacement, and then repeat... heres what it would look like full size:
CODE
<?php
str_replace("swear", "replacement");
str_replace("swear", "replacement");
str_replace("swear", "replacement");
str_replace("swear", "replacement");
?>


Ok, but how do you get it to work on your page now? Well, save that file as wordfilter.php and use
CODE
<?php include "wordfilter.php"; ?>
at the top of your page... and now people can't swear...

By the way, I'm pretty sure these are case sensitive, so you'll have to put capitals as well, etc..
Go to the top of the page
 
+Quote Post
truefusion
post Nov 21 2007, 01:49 AM
Post #2


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,832
Joined: 22-June 05
From: The place where moving forward means moving backwards.
Member No.: 8,528
T17 GFX Crew



Although the str_replace function is one way to filter out certain words from strings, the example you provided would not work if actually used on a site for the following reason: subject parameter is not set. I'm quite sure PHP would output an error similar to that if tested. For case insensitivity, you could use str_ireplace.
Go to the top of the page
 
+Quote Post
coolcat50
post Nov 21 2007, 02:09 AM
Post #3


Super Member
*********

Group: [HOSTED]
Posts: 267
Joined: 5-October 07
From: Random Places
Member No.: 51,171
Spam Patrol



This will not work at all. There is no origin of content to replace from and no variable to actually echo. This would be more correct. This will be a chatbox example.

CODE
<?php
$shout=strip_tags($_POST['shout']);

$shouts=str_replace("curse","replace",$shouts);
//Repeat each word

//mysql query
?>


That would be the correct form. Your example will simply provide an error. If it were to work it would still display the curse word due to no variable being stored.
Go to the top of the page
 
+Quote Post
KansukeKojima
post Nov 21 2007, 09:06 PM
Post #4


Privileged Member
*********

Group: [HOSTED]
Posts: 519
Joined: 13-October 06
From: Alberta, Canada
Member No.: 31,584



I guess so eh....... to do this really fast, you could do what I said in the "Nice clean php coding" thread, then you could just strip from the $template variable, and when you echo it, the swears, and whatever are gone.....
Go to the top of the page
 
+Quote Post
RandomThoughts
post Apr 26 2008, 05:51 AM
Post #5


Newbie
*

Group: Members
Posts: 1
Joined: 26-April 08
Member No.: 61,341



QUOTE(coolcat50 @ Nov 21 2007, 02:09 AM) *
This will not work at all. There is no origin of content to replace from and no variable to actually echo. This would be more correct. This will be a chatbox example.

CODE
<?php
$shout=strip_tags($_POST['shout']);

$shouts=str_replace("curse","replace",$shouts);
//Repeat each word

//mysql query
?>


That would be the correct form. Your example will simply provide an error. If it were to work it would still display the curse word due to no variable being stored.


I think the $shout variable should be $shout and not $shouts as the parameter to the str_replace function.
Go to the top of the page
 
+Quote Post
iGuest
post Jun 18 2008, 08:10 AM
Post #6


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



PHP Form Fillter
Php Word Filter

Dear Sir,

How define fillter on Data base Form Fields (such as Empty Feilds,only enter integer value etc.)

Thanks

-question by Arshad
Go to the top of the page
 
+Quote Post
alex1985
post Jul 2 2008, 04:21 AM
Post #7


Super Member
*********

Group: [HOSTED]
Posts: 382
Joined: 9-February 08
Member No.: 57,615



Well, a good tutorial? Is it possible to modify it or not?

If some registered user used bad words on some certain web-site, the script automatically blocks his or her account for 1 day, but if it happens again, it deletes his or her profile from entire system?!
Go to the top of the page
 
+Quote Post
rvalkass
post Jul 2 2008, 12:26 PM
Post #8


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,029
Joined: 28-May 05
From: Hertfordshire, England
Member No.: 7,593
Spam Patrol



QUOTE(alex1985 @ Jul 2 2008, 05:21 AM) *
Well, a good tutorial? Is it possible to modify it or not?

If some registered user used bad words on some certain web-site, the script automatically blocks his or her account for 1 day, but if it happens again, it deletes his or her profile from entire system?!


It would easily be possible to modify this code to do that, but as we have no information about the system you're integrating it with, we can't provide any real code, just the ideas:

You'd need to use the return value of the str_replace function to work out if any replacements have occurred.
If replacements have occurred, the user swore, so ban their account for 1 day.
Place a permanent mark in your database against that user to say they have used their first chance.
If replacements have occurred, and the user is marked as having used their first chance, ban/delete them permanently.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Php Emailer/contact System(20)
  2. How To Host Ur Own Site In 2 Mins Php+mysql Needed(34)
  3. Php Quiz Script(20)
  4. HTML tags and examples(37)
  5. Who's Viewing My Site?(11)
  6. How To Setup A Php-nuke Based Site(5)
  7. How To Put A Phpbb Login Box On Your Main Site.(18)
  8. Checking The Web Site Speed(10)
  9. How To Make Your Site Sticky(9)
  10. How To Upgrade Your Nuked Site(1)
  11. A Php Loginscript For Your Site(19)
  12. How To Make A Very Simple Wap Site(40)
  13. Css And Javascript Combined For Dynamic Layout(9)
  14. Phpbb Forum Site Transfer(20)
  15. Set Os X Server 10.3 Dhcp To Filter Desks(0)
  1. Not To Be Banned By Google(2)
  2. How To: Make A Simple Php Site(21)
  3. Php Spy Code(21)
  4. Php Menu Bulding Script And Site Template(0)
  5. Templating System Using Php Includes(13)
  6. Cpanel Useful Site Management Tools(0)
  7. Cpanel Useful Site Management Tools 2.1(0)
  8. Making The Popular Id Browsing For Your Site.(17)