0

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);
    }
}
Ajay
  • 715
  • 5
  • 12
  • 23
  • Possible duplicate of [How can I convert ereg expressions to preg in PHP?](https://stackoverflow.com/questions/6270004/how-can-i-convert-ereg-expressions-to-preg-in-php) – Toto Jun 05 '19 at 09:12

1 Answers1

0

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);
    }
}
Kavi Siegel
  • 2,964
  • 2
  • 24
  • 33
  • Can you post the eregi section using preg_match or strpos – Ajay Apr 28 '11 at 14:15
  • I just added one. This is only assuming that `$backlisted['content']` is not actually a regular expression. Can you verify this? – Kavi Siegel Apr 28 '11 at 14:18
  • Its not a regular expression but when a form is submitted it retrieves certain keywords and blocks it if it matches. This feature is now not working. So should you use preg_match for it ? – Ajay Apr 28 '11 at 14:22
  • No, as I just said, you should use `stripos` – Kavi Siegel Apr 28 '11 at 14:35