Page 1 of 1

Wild cards (*) in Arrays

Posted: Tue Aug 19, 2008 7:55 pm
by BillBillJr
Hello, I was wondering if you can implement wildcards (*) when searching an array. What I am trying to do is configure a spam-detecting script, if the script find said spam, the website or link will be starred out. For example: if a user puts "Discount watches at http://www.site.com! into the message I want the script to edit the website out so it appears as "Discount watches at http://www.****.***! Here is some starting code:

Code: Select all

<?php
/* From a previous form. */
$message = $_POST['message'];
 
/* Anything using site.whatever, site DOT whatever, site(.)whatever, site[.]whatever, and site dot whatever is dubbed spam. */
$spam = array("*.*", "*DOT*", "*(.)*", "*[.]*", "*dot*");
 
/* Searches the message to see if there is any spam, if there is spam then edit it out, otherwise send the message. */
if (in_array($message, $array)){
    some code
}else{
    echo "Your message has been posted!";
}
?>
 
 
If wildcards can, infact, be used can you please check my code to see it I used it correctly. Thanks! :D

Re: Wild cards (*) in Arrays

Posted: Tue Aug 19, 2008 8:55 pm
by kalebaustin
in_array won't work as you intend.
You'll want preg_match, or preg_replace combined with regex.
Rexeg would be what you're calling 'wild cards'.

Re: Wild cards (*) in Arrays

Posted: Wed Aug 20, 2008 12:13 am
by nowaydown1
I have to agree with kalebaustin. Regex would be the way to go.