Wild cards (*) in Arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BillBillJr
Forum Newbie
Posts: 9
Joined: Tue Aug 19, 2008 7:43 pm
Location: U.S.A.

Wild cards (*) in Arrays

Post 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
kalebaustin
Forum Newbie
Posts: 12
Joined: Mon Nov 19, 2007 11:28 am

Re: Wild cards (*) in Arrays

Post 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'.
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: Wild cards (*) in Arrays

Post by nowaydown1 »

I have to agree with kalebaustin. Regex would be the way to go.
Post Reply