PHP Regular Expression processing method

Source: Internet
Author: User

This article mainly share with you two PHP regular expression processing method, hope to help everyone.

1. Processing Chinese characters
For example: Software engineering major [up]
Acquisition: Major in Software engineering

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 = ' $ ';                $newmajor = Preg_replace ($pattern, $replace, $major);                $info [' major '] = $newmajor;                M (' Enroll_major ')->update ($info);            }            Include $this->template (' index ');    }

2. A001 Peking University
Separating out code and text

    Public Function Domobilealtername () {        global $_w,$_gpc;        for ($id =1; $id <=1225; $id + +) {            $info = M (' enroll_science ')->getinfo ($id);            $pattern 1 = '/\w\d+ ([\s|\s]+)/I ';            $replacement 1 = ' $ ';            $newname =  Preg_replace ($pattern 1, $replacement 1, $info [' name ']);            $pattern 2 = '/(\w\d+) ([\s|\s]+)/I ';            $replacement 2 = ' $ ';            $newcode =  Preg_replace ($pattern 2, $replacement 2, $info [' name ']);            $info [' name '] = $newname;            $info [' zscode '] = $newcode;            M (' enroll_science ')->update ($info);        }            Include $this->template (' index ');    }

1. Processing Chinese characters
For example: Software engineering major [up]
Acquisition: Major in Software engineering

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 = ' $ ';                $newmajor = Preg_replace ($pattern, $replace, $major);                $info [' major '] = $newmajor;                M (' Enroll_major ')->update ($info);            }            Include $this->template (' index ');    }

2. A001 Peking University
Separating out code and text

 Public function domobilealtername () {Global $_W,$_GPC;            for ($id =1; $id <=1225; $id + +) {$info = M (' enroll_science ')->getinfo ($id);            $pattern 1 = '/\w\d+ ([\s|\s]+)/I ';            $replacement 1 = ' $ ';            $newname = Preg_replace ($pattern 1, $replacement 1, $info [' name ']);            $pattern 2 = '/(\w\d+) ([\s|\s]+)/I ';            $replacement 2 = ' $ ';            $newcode = Preg_replace ($pattern 2, $replacement 2, $info [' name ']);            $info [' name '] = $newname;            $info [' zscode '] = $newcode;        M (' enroll_science ')->update ($info);    } include $this->template (' index '); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.