不推荐使用:函数ereg()不推荐使用 [英] Deprecated: Function ereg() is deprecated
问题描述
Possible Duplicate:
How can I convert ereg expressions to preg in PHP?
我的联系表可以正常使用,但是我一直在收到以下信息 错误:
My contact form is othervise working but I keep getting the following error:
已弃用:函数ereg()在/home/......
Deprecated: Function ereg() is deprecated in/home/.....
我真的迷失了,但是我认为这是需要调整的部分.
I'm really lost here but I figure this is the part that needs some adjusting.
if ( empty($_REQUEST['name']) ) {
$pass = 1;
$alert .= $emptyname;
} elseif ( ereg( "[][{}()*+?.\\^$|]", $_REQUEST['name'] ) ) {
$pass = 1;
$alert .= $alertname;
}
if ( empty($_REQUEST['email']) ) {
$pass = 1;
$alert .= $emptyemail;
} elseif ( !eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z] {2,3})$", $_REQUEST['email']) ) {
$pass = 1;
$alert .= $alertemail;
}
if ( empty($_REQUEST['message']) ) {
$pass = 1;
$alert .= $emptymessage;
} elseif ( preg_match( "[][{}()*+?\\^$|]", $_REQUEST['message'] ) ) {
$pass = 1;
$alert .= $alertmessage;
}
高度赞赏找到解决方案的人
Finding a solution would be highly appreciated
推荐答案
您必须使用 ereg
,因为不推荐使用最后一个.
You must use preg_match
instead of ereg
because the last one is deprecated.
替换它没什么大不了的:
Replacing it is not a big deal:
ereg( "[][{}()*+?.\\^$|]", $_REQUEST['name'] )
将变为:
preg_match( "/[][{}()*+?.\\^$|]/", $_REQUEST['name'] )
p.s.在将旧项目移植到PHP 5.3的过程中,我不得不修改了一百多个文件,以避免手动修改,我使用以下脚本为我完成此操作:
p.s. I had to modify more than one hundred files while I was porting my old project to PHP 5.3 to avoid manually modifying I've used following script to do it for me:
function replaceEregWithPregMatch($path) {
$content = file_get_contents($path);
$content = preg_replace('/ereg\(("|\')(.+)(\"|\'),/',
"preg_match('/$2/',",
$content);
file_put_contents($path, $content);
}
希望对您有帮助.
这篇关于不推荐使用:函数ereg()不推荐使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!