phpRegex處理方法

來源:互聯網
上載者:User

本文主要和大家分享兩個phpRegex處理方法,希望能協助到大家。

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');    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.