Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-19-2007, 04:51 PM Array of Words
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
i have a array with words i want to not be allowed to be used in the form submit.
my array is:
PHP Code:
$global_badwords = array("bad1","bad2","bad3"); 
and i have the form, so on the next page when the values are entered into the database here:
PHP Code:
if (isset($_POST['name'])) {
    
$name=$_POST['name'];
    if (
$name == "") {
        echo 
"<b><center>You didn't enter anything!</center></b>";
    } elseif (
$name == "$global_badwords") {
        echo 
"<b><center>That is not your name</center></b>";
    } else {
    
mysql_query($sql1);
    echo 
"<b><center>Added $name to $result_event!</center></b>";
    }

but it does not block those words?

thanks
melefire is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-19-2007, 05:04 PM Re: Array of Words
Novice Talker

Posts: 13
Name: hach22
Trades: 0
PHP Code:
elseif (in_array($name$global_badwords)) {
        echo 
"<b><center>That is not your name</center></b>"
http://www.php.net/manual/en/function.in-array.php
hach22 is offline
Reply With Quote
View Public Profile
 
Old 12-19-2007, 05:25 PM Re: Array of Words
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
thanks, that worked
melefire is offline
Reply With Quote
View Public Profile
 
Old 12-19-2007, 06:40 PM Re: Array of Words
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
I don't know PHP.

How does it do string comparisons? Does hi = HI? In .NET, we can use an overload of String.Compare that tells it to do case (in)sensitive comparisons when we want to. People who don't stay up to date usually wind up doing a string.ToUpper() against both. So if someone types hi and your word list has HI or Hi it still gets caught.

--------------------------------------------------------------------------------

Ask yourself if these should go in a table in a database? That would make it a lot easier for you to change anything (like add more words) down the line. But it would also be quicker. At least if you have more than 3 or 4 bad words. Throw an index on the table, and let SQL do its thing. Just seems like that might be better all around?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 12-20-2007, 04:49 AM Re: Array of Words
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
Quote:
How does it do string comparisons? Does hi = HI? In .NET, we can use an overload of String.Compare that tells it to do case (in)sensitive comparisons when we want to. People who don't stay up to date usually wind up doing a string.ToUpper() against both. So if someone types hi and your word list has HI or Hi it still gets caught.
In PHP some functions are case sensitive and some is case insensitive. Most of functions have both version especialy string functions. For example, strstr find first occurrence of a string and it is case sensitive, stristr do the same but it is case insensitive.

Shivaji
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels

Last edited by shivaji; 12-20-2007 at 04:53 AM..
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 12-20-2007, 12:24 PM Re: Array of Words
Skilled Talker

Posts: 62
Name: Daniel
Trades: 0
PHP Code:
<?php
if ("hi" == "HI") {
 echo 
"true";
} else {
 echo 
"false";
}
?>
will return false.

short and sweet.
castis is offline
Reply With Quote
View Public Profile
 
Old 12-21-2007, 05:05 AM Re: Array of Words
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You can use preg_match() and keep your bad words as a regexp instead of array to get more power and flexibility, because with regexps you will be able to ignore case and make tests like whether it is a whole word or a part of, etc.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-21-2007, 07:59 AM Re: Array of Words
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
You could, at runtime, compile the array into a string for use as a regexp if you had to, or just do that when you add to the array and put the regexp as static.
__________________
Foundation Flash tutorials :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 12-23-2007, 08:05 PM Re: Array of Words
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
how would i use the preg_match() exactly?
melefire is offline
Reply With Quote
View Public Profile
 
Old 12-24-2007, 02:13 AM Re: Array of Words
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Code:
$disallowed "!word1|word2|\bword3\b|word4.*!i";
if (
preg_match($disallowed$user_input))
   echo 
"Your input contains disallowed words"
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-24-2007, 07:57 PM Re: Array of Words
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
thanks
melefire is offline
Reply With Quote
View Public Profile
 
Old 01-21-2008, 09:27 PM Re: Array of Words
carloncho's Avatar
Skilled Talker

Posts: 80
Name: Carlos
Trades: 0
You equal a string with an array. This is the problem. You must equal each member of the array with your string. The in_array function is the solution. (http://www.php.net/in_array)
__________________
-----------------------

Please login or register to view this content. Registration is FREE
carloncho is offline
Reply With Quote
View Public Profile Visit carloncho's homepage!
 
Reply     « Reply to Array of Words
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.56847 seconds with 12 queries