Mourning the loss of our friend, WhitPhil.
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 audio black screen blue screen boot bsod connection crash dell desktop driver drivers dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor network networking outlook problem processor recovery registry cleaner router safe mode slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
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

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Senior Member with 187 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
05-Oct-2009, 10: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
Senior Member with 413 posts.
 
Join Date: Apr 2007
Experience: Excel, Access, PHP, Js
08-Oct-2009, 11:53 AM #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
Senior Member with 187 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
08-Oct-2009, 12: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
Senior Member with 413 posts.
 
Join Date: Apr 2007
Experience: Excel, Access, PHP, Js
08-Oct-2009, 01: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
Senior Member with 187 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
08-Oct-2009, 02: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
Senior Member with 413 posts.
 
Join Date: Apr 2007
Experience: Excel, Access, PHP, Js
08-Oct-2009, 04: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
Senior Member with 187 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
08-Oct-2009, 04: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>");}}
Closed Thread Bookmark and Share

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.

Smart Search

Find your solution!



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


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 02:17 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.