There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus batch bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop lcd malware memory modem monitor motherboard network printer problem ram registry router slow software sound toshiba trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
how can i create a php filter to filter out words that are in a text file

Reply  
Thread Tools
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Member with 195 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
05-Oct-2009, 11:49 AM #1
Question how can i create a php filter to filter out words that are in a text file
like for registration at my site there cant be usernames of about 50 words i can think of they can all be listed in a text file separated by a space but how do i create a php code for it to check if the username the person chose is one of the 500 words that its not supposed to be?
MRdNk's Avatar
Computer Specs
Member with 439 posts.
 
Join Date: Apr 2007
Location: UK
Experience: Damn I'm good!
08-Oct-2009, 12:53 PM #2
Hi emopoops,

This'll give you what you need.

PHP Code:
<?PHP

// PHP function that does the work
function check_username($input){

    
$input strtolower($input);

    
$file_handle fopen("filename.txt""rb");
    
    while (!
feof($file_handle)) {
    
        
$line_of_text fgets($file_handle);
        
$parts explode(' '$line_of_text);

        foreach(
$parts as $value){
            
$value strtolower($value);
            if(
$input == $value){
                return 
0;
            }
        }
    }
    return 
1;
    
fclose($file_handle);
}

//Example of use

$username "One";

$result check_username($username);

if(
$result == 0){
    echo 
'Username not allowed';
}
else{
    echo 
'Username accepted';
}
?>
Obviously you can build this into your current username functions.
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Member with 195 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
08-Oct-2009, 01:33 PM #3
thanks thats a good way of doing it. just make sure the words are seperated by a space no commas or anything?
MRdNk's Avatar
Computer Specs
Member with 439 posts.
 
Join Date: Apr 2007
Location: UK
Experience: Damn I'm good!
08-Oct-2009, 02:42 PM #4
Yes, you can change it to a different delimiter, in the explode parameters.
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Member with 195 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
08-Oct-2009, 03:17 PM #5
oh i think im just goingto use this one i figured out. it has like checking for not the exact match but if it contains it.
MRdNk's Avatar
Computer Specs
Member with 439 posts.
 
Join Date: Apr 2007
Location: UK
Experience: Damn I'm good!
08-Oct-2009, 05:18 PM #6
Sounds interesting, please post it - only problem with contains imo is that a persons name may genuinely contain a "dodgy" word - but you can't solve all possible issues. I would just be careful not to limit usernames too much.
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Member with 195 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
08-Oct-2009, 05:27 PM #7
ok heres the code:
Code:
$lowercaseusername = preg_replace("/[^a-z]/i", "", $username);
$lowercaseusername = strtolower($lowercaseusername);

$banned = array("scenequeen", "hater", "skank", "emopoops",  "etc...");

$trimthex = str_replace('x', '', $lowercaseusername);

    foreach ($banned as $singleword){
        if (strstr($trimthex, $singleword) != FALSE){
        exit("<center>$username has $singleword in it!<br>
you cannot have $singleword in your usernname!<br><a style='color:deeppink;font-weight:bold;text-decoration:none;cursor:crosshair' href='register.php'>try again?</a></center>");}}
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:15 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.