本文主要和大家分享两个php正则表达式处理方法,希望能帮助到大家。
1、处理汉字
例如:软件工程专业[1,2]
获取:软件工程专业
public function doMobilealtermajor(){ global $_W,$_GPC; $_GPC['do']='altercode'; for($i=1;$i<=29083 ;$i++){ $info = M('enroll_major')->getInfo($i); $major = $info['major']; iconv("gbk","utf-8",$major); $pattern = '/([\x{4e00}-\x{9fa5}]+)(\[\d,\d\])/u'; $replace = '$1'; $newmajor = preg_replace($pattern,$replace,$major); $info['major'] = $newmajor; M('enroll_major')->update($info); } include $this->template('index'); }
2、A001北京大学
分离出代码和文字
public function doMobilealtername(){ global $_W,$_GPC; for($id=1;$id<=1225;$id++){ $info = M('enroll_science')->getInfo($id); $pattern1 = '/\w\d+([\S|\s]+)/i'; $replacement1 = '$1'; $newname = preg_replace($pattern1, $replacement1, $info['name']); $pattern2 = '/(\w\d+)([\S|\s]+)/i'; $replacement2 = '$1'; $newcode = preg_replace($pattern2, $replacement2,$info['name']); $info['name'] = $newname; $info['zscode'] = $newcode; M('enroll_science')->update($info); } include $this->template('index'); }
1、处理汉字
例如:软件工程专业[1,2]
获取:软件工程专业
public function doMobilealtermajor(){ global $_W,$_GPC; $_GPC['do']='altercode'; for($i=1;$i<=29083 ;$i++){ $info = M('enroll_major')->getInfo($i); $major = $info['major']; iconv("gbk","utf-8",$major); $pattern = '/([\x{4e00}-\x{9fa5}]+)(\[\d,\d\])/u'; $replace = '$1'; $newmajor = preg_replace($pattern,$replace,$major); $info['major'] = $newmajor; M('enroll_major')->update($info); } include $this->template('index'); }
2、A001北京大学
分离出代码和文字
public function doMobilealtername(){ global $_W,$_GPC; for($id=1;$id<=1225;$id++){ $info = M('enroll_science')->getInfo($id); $pattern1 = '/\w\d+([\S|\s]+)/i'; $replacement1 = '$1'; $newname = preg_replace($pattern1, $replacement1, $info['name']); $pattern2 = '/(\w\d+)([\S|\s]+)/i'; $replacement2 = '$1'; $newcode = preg_replace($pattern2, $replacement2,$info['name']); $info['name'] = $newname; $info['zscode'] = $newcode; M('enroll_science')->update($info); } include $this->template('index'); }
相关推荐:
Das obige ist der detaillierte Inhalt vonVerarbeitungsmethode für reguläre PHP-Ausdrücke. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!