不推荐使用函数eregi()。我该如何替换eregi()。我尝试使用preg_match,但随后停止工作。
之前的代码:
if ( ! eregi("convert$", $this->library_path)) { if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; $this->library_path .= 'convert'; } if (eregi("gd2$", $protocol)) { $protocol = 'image_process_gd'; }
代码然后:
if ( ! preg_match("convert$/i", $this->library_path)) { if ( ! preg_match("/$/i", $this->library_path)) $this->library_path .= "/"; $this->library_path .= 'convert'; } if (preg_match("gd2$/i", $protocol)) { $protocol = 'image_process_gd'; }
preg_match 期望其正则表达式参数位于一对定界符内。
preg_match
因此,请尝试:
if ( ! preg_match("#convert$#i", $this->library_path)) { if ( ! preg_match("#/$#i", $this->library_path)) $this->library_path .= "/"; $this->library_path .= 'convert'; } if (preg_match("#gd2$#i", $protocol)) { $protocol = 'image_process_gd'; }