请帮我将此代码转换为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);
}
}
答案 0 :(得分:0)
eregi
来查看一个字符串是否在另一个字符串中。这不是正确的用途。您可以使用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);
}
}