Getting Error mb_eregi(): mbregex compile err: target of repeat operator is invalid

692 Views Asked by At
if(mb_eregi("\b{$value}\b",$tmp))
{
    $has_fw++;
    $tmp = mb_eregi_replace("\b({$value})\b","***",$tmp);
}

I am not able to find anything about this error on the web. What is causing this error?

1

There are 1 best solutions below

0
Zach On

Try:

$match = sprintf('\b%s\b', $value);
$capture_match = sprintf('\b(%s)\b', $value);
if (mb_eregi($match, $tmp))
{
  $has_fw++;
  $tmp = mb_eregi_replace($capture_match, '***', $tmp);
}

Using {} inside of a regex makes the function think you're trying to find a repeating value when it looks like you didn't intend to use the {} as a regex operator, but instead you intended it to evaluate $value, which isn't the case inside of a regex.