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代替

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