SFB Posted June 21, 2006 Share Posted June 21, 2006 i just got a spam message on my message board. I am adding a script that will look in a list of words that a spammer might use but a normal poster probably wouldnt. i will also add ip addresses and usernames to the list. I am having troubles making the list into an array. i could go like $spam[0] = "blah";$spam[1] = "blah";$spam[2] = "blah";$spam[3] = "blah"; but i would rather just have a list like$spam = "blah";$spam = "blah";$spam = "blah";where i do not have to change the numbers in the brackets. this seeems like it would be posilbe but i am just confused as to how i would do it. Link to comment Share on other sites More sharing options...
aleksanteri Posted June 21, 2006 Share Posted June 21, 2006 It could be: $spam = array("blah", "blah");// add another spam$spam[] = "blah"; SO: You can leave the index out! PHP will add the index automaticly. Link to comment Share on other sites More sharing options...
SFB Posted June 21, 2006 Author Share Posted June 21, 2006 so could i go like $spam = array();$spam[] = "blah"; Link to comment Share on other sites More sharing options...
justsomeguy Posted June 21, 2006 Share Posted June 21, 2006 That's right, it's called a "push". Both of these do the same thing:$array[] = $new;array_push($array, $new);http://www.php.net/manual/en/function.array-push.php Link to comment Share on other sites More sharing options...
SFB Posted June 21, 2006 Author Share Posted June 21, 2006 ok, thanks Link to comment Share on other sites More sharing options...
SFB Posted June 21, 2006 Author Share Posted June 21, 2006 so far i got include('/sfb/mb/filter.php');$count = "0";for ($i = 0; $i < count($blocked); $i++){ $look = substr_count("$mg", "$spam[$i]"); $count+$look;}if($look >= "2"){ print'please try not to use words that spammers may use'; $mg = ""; exit;} the only part i was wondering about was the part where i add count and looki know you can add one to count like $count++; i'm just not confident this is how i should add count and look together. Link to comment Share on other sites More sharing options...
SFB Posted June 21, 2006 Author Share Posted June 21, 2006 ok i simplified it. but it still doesnt work $spam = array();$spam[] = "morgage";$spam[] = "mortgages.advancegrouponline.com";$spam[] = "refinance";$spam[] = "vladislav_ivashu@mail.ru";$spam[] = "mrtgage123r";$spam[] = "######";$spam[] = "pills";$spam[] = "buy";$spam[] = "medicine";$spam[] = "enlarge";$spam[] = "credit";$spam[] = "credit card";$spam[] = "sign up"; for ($i = 0; $i < count($spam); $i++){ $look = substr_count("$mg", "$spam[$i]"); if($look != "0") { print"DO NOT SPAM"; $mg = ""; exit; }} Link to comment Share on other sites More sharing options...
SFB Posted June 21, 2006 Author Share Posted June 21, 2006 ok i simplified it. but it still doesnt work $spam = array();$spam[] = "morgage";$spam[] = "mortgages.advancegrouponline.com";$spam[] = "refinance";$spam[] = "vladislav_ivashu@mail.ru";$spam[] = "mrtgage123r";$spam[] = "######";$spam[] = "pills";$spam[] = "buy";$spam[] = "medicine";$spam[] = "enlarge";$spam[] = "credit";$spam[] = "credit card";$spam[] = "sign up"; for ($i = 0; $i < count($spam); $i++){ $look = substr_count("$mg", "$spam[$i]"); if($look != "0") { print"DO NOT SPAM"; $mg = ""; exit; }} <{POST_SNAPBACK}> got it working... my error was a result of coppy and paste. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 21, 2006 Share Posted June 21, 2006 You can simplify it a little more. And you don't need to quote every variable, I don't know why people do that (see the substr_count call, you don't need to quote a variable if you are only using the variable). for ($i = 0; $i < count($spam); $i++){ if(substr_count($mg, $spam[$i]) > 0) { print "DO NOT SPAM"; exit(); }} Also, for future reference, $count += $look will add $look to $count and save it in $count. Link to comment Share on other sites More sharing options...
SFB Posted June 22, 2006 Author Share Posted June 22, 2006 for ($i = 0; $i < count($spam); $i++){ if((substr_count($body, $spam[$i]) > 0) or (substr_count($ip, $spamip[$i]) > 0)) { print "DO NOT SPAM"; exit(); }} this is what i use now. its got an ip blocker added to it. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 22, 2006 Share Posted June 22, 2006 One thing you might want to do is convert everything to the same case before you compare, string comparisons are case-sensitive. Since you aren't concerned with how many times the substring appears, you can use a case-insensitive search function instead of substr_count. This will also be a little faster than substr_count, because you aren't concerned with how many times it appears, just if it appears at all.if((stripos($body, $spam[$i]) !== false) or (stripos($ip, $spamip[$i]) !== false)) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now