208 preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

一开始没注意,后来发现 很多这样的警告,于是网上查了下 发现 php5.5版本以上 就废弃了  preg_replace   函数中 /e 这个修饰符  /e 这个修饰符的意思 就是让 正则替换的 时候 替换规则 支持 php 代码 

if($back == 0){
			return preg_replace('/(.)/es',"str_pad(base_convert(ord('\\1'),10,$tobase),2,'0',STR_PAD_LEFT)",$string);
		}else{
			return preg_replace('/(\w{2})/e',"chr(base_convert('\\1',$tobase,10))",$string);
		}
if($back == 0)
        {
            return preg_replace_callback('/(.)/s',
                function ($matches) use($tobase)
                {
                    return str_pad(base_convert(ord($matches[1]), 10, $tobase), 2, '0', STR_PAD_LEFT);
                },
                $string
            );
        }
        else
        {
            return preg_replace_callback('/(\w{2})/',
                function ($matches) use($tobase)
                {
                    return chr(base_convert($matches[1], $tobase, 10));
                },
                $string
            );
        }

用preg_replace_callback代替

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章