时间:2021-07-01 10:21:17 帮助过:4人阅读
本文主要和大家分享两个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'); }
相关推荐:
PHP正则表达式分组捕获实现方法
猪哥深谈php正则表达式及正则表达式都用在什么地方?
PHP正则表达式的基础及简单实例
以上就是php正则表达式处理方法的详细内容,更多请关注Gxl网其它相关文章!