php – 函数eregi()已弃用
作者:互联网
参见英文答案 > How can I convert ereg expressions to preg in PHP? 4个
函数eregi()已弃用.我怎样才能取代eregi().我尝试使用preg_match然后停止工作.
我们帮助他们:
http://takien.com/513/how-to-fix-function-eregi-is-deprecated-in-php-5-3-0.php
代码之前:
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期望它的正则表达式参数在一对分隔符内.
所以尝试:
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';
}
标签:eregi,php,regex,preg-match 来源: https://codeday.me/bug/20190919/1812392.html