preg_match for regex expression

127 Views Asked by At

Please help me to convert this code to preg_match

$blacklist = $db->query("SELECT `content` FROM `" . TABLE_PREFIX . "blacklist` WHERE `type`='$type'");
while ($blacklisted = $db->fetch_array($blacklist))
{
    if (is_array($input))
    {
        foreach ($input as $entry)
        {
            if (eregi($blacklisted['content'], $entry))
                print_error($msg);
        }
    }
    else if (eregi($blacklisted['content'], $input))
    {
        print_error($msg);
    }
}
1

There are 1 best solutions below

4
Kavi Siegel On BEST ANSWER

eregi used to be used like that to see if one string is in another. It was not the proper use. You can do the same with stripos

$blacklist = $db->query("SELECT `content` FROM `" . TABLE_PREFIX . "blacklist` WHERE `type`='$type'");
while ($blacklisted = $db->fetch_array($blacklist))
{
    if (is_array($input))
    {
        foreach ($input as $entry)
        {
            if (false !== stripos($entry, $blacklisted['content']))
                print_error($msg);
        }
    }
    else if (false !== stripos($input, $blacklisted['content']))
    {
        print_error($msg);
    }
}