Syntax help - Convert Eregi_replace to preg_replace in PHP

126 Views Asked by At

We just upgrade to PHP7 and the eregi function is now not working and I need to convert it to preg_replace. I've looked over a couple other topics which are requesting the same thing. I am having an issue with the syntax.

Current code

$body = eregi_replace("[\]", '', $body);

I've tried the following but it looks like it's not fully working as $body looks to be empty.

$body = preg_replace('[\]', '', $body);

Any help would be appreciated.

1

There are 1 best solutions below

0
Samuel James On

Why not just check if $body is not empty

if($body!=null) {
$body = preg_replace('[\]', '', $body);

}