|
|
|
|
![]() ![]() |
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.. |
|
|
|
Nov 21 2007, 01:49 AM
Post
#2
|
|
|
Ephesians 6:10-17 ![]() Group: [MODERATOR] Posts: 1,832 Joined: 22-June 05 From: The place where moving forward means moving backwards. Member No.: 8,528 ![]() |
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.
|
|
|
|
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 ![]() |
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. |
|
|
|
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.....
|
|
|
|
Apr 26 2008, 05:51 AM
Post
#5
|
|
|
Newbie ![]() Group: Members Posts: 1 Joined: 26-April 08 Member No.: 61,341 |
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. |
|
|
|
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 |
|
|
|
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?! |
|
|
|
Jul 2 2008, 12:26 PM
Post
#8
|
|
|
apt-get moo ![]() Group: [MODERATOR] Posts: 2,029 Joined: 28-May 05 From: Hertfordshire, England Member No.: 7,593 ![]() |
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. |
|
|
|
![]() ![]() |
Similar Topics