duanjianqu3685 2013-08-20 15:01
浏览 71
已采纳

php函数弃用,将ereg_replace更改为preg_replace

if ($js_enabled == "Y") {
    $qry_string = ereg_replace("(&*)js=y", "", $QUERY_STRING);
    $js_update_link = $PHP_SELF."?".($qry_string?"$qry_string&":"")."js=n";
}
else {
    $qry_string = ereg_replace("(&*)js=n", "", $QUERY_STRING);
    $js_update_link = $PHP_SELF."?".($qry_string?"$qry_string&":"")."js=y";
}

ereg_replace is deprecated and I would like to switch this to preg_replace, but the regular expression would be different right?

How would I patch this?

  • 写回答

1条回答 默认 最新

  • dongqian9567 2013-08-20 15:02
    关注
    if ($js_enabled == "Y") {
        $qry_string = preg_replace("/(&*)js=y/", "", $QUERY_STRING);
        $js_update_link = $PHP_SELF."?".($qry_string?"$qry_string&":"")."js=n";
    }
    else {
        $qry_string = preg_replace("/(&*)js=n/", "", $QUERY_STRING);
        $js_update_link = $PHP_SELF."?".($qry_string?"$qry_string&":"")."js=y";
    }
    

    preg is faster and uses a PERL-style syntax (as opposed to the old Postfix style), so you may need some slight adjustments in the expression.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部