重建(替换)一些被 PHP7 废弃的函数
if(!function_exists(‘ereg’)) { function ereg($pattern, $subject, &$matches = []) { return preg_match(‘/’.$pattern.’/', $subject, $matches); } }
if(!function_exists(‘eregi’)) { function eregi($pattern, $subject, &$matches = []) { return preg_match(‘/’.$pattern.’/i’, $subject, $matches); } }
if(!function_exists(‘ereg_replace’)) { function ereg_replace($pattern, $replacement, $string) { return preg_replace(‘/’.$pattern.’/', $replacement, $string); } }
if(!function_exists(‘eregi_replace’)) { function eregi_replace($pattern, $replacement, $string) { return preg_replace(‘/’.$pattern.’/i’, $replacement, $string); } }
if(!function_exists(‘split’)) { function split($pattern, $subject, $limit = -1) { return preg_split(‘/’.$pattern.’/', $subject, $limit); } }
if(!function_exists(‘spliti’)) { function spliti($pattern, $subject, $limit = -1) { return preg_split(‘/’.$pattern.’/i’, $subject, $limit); } }
温馨提示
有些地方替换函数中的 / 可能会报错,可以将 / 换成 ~,比如:
return preg_match(‘/’.$pattern.’/i’, $subject, $matches); 改为: return preg_match(‘~’.$pattern.’~i’, $subject, $matches);