函数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';
}发布于 2011-04-18 17:22:35
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';
} 发布于 2011-04-18 17:20:52
你好像忘了分隔符
preg_match("~/$~", $this->library_path)和
preg_match("~gd2$~i", $protocol)但在这两种情况下,您都应该考虑不使用正则表达式,因为它们在这里太大了
$this->library_path[strlen($this->library_path) - 1] == '/'
substr($protocol, -3) == 'gd2'发布于 2011-04-18 17:39:02
如果只是检查一个字符串中是否存在另一个字符串,则应该只使用strpos()函数。例如:
if(strpos('convert', $this->library_path) !== false) {
// code here
}更新:误读你想要在字符串的末尾检查它,这仍然可以通过使用substr()在没有正则表达式的情况下进行
if(substr($this->library_path, -7) == 'convert' {
//code here
}其中7是convert的长度,您可以使用一个字符串并从0中减去它,以动态地获得这个数字。这不会启动任何正则表达式,因此效率更高。
https://stackoverflow.com/questions/5700806
复制相似问题