This line needs to be `$file = preg_replace($regex, '', $file);`.