不推荐使用:函数ereg()不推荐使用 [英] Deprecated: Function ereg() is deprecated

查看:170
本文介绍了不推荐使用:函数ereg()不推荐使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何在PHP中将ereg表达式转换为preg?/a>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆