1 PHP regular expression

Source: Internet
Author: User
For example, if you want to find a PHP regular expression, you can find a PHP regular expression like, which contains many Chinese characters! I want to store each word in an array, where an English word is stored in a unit, for example, {& quot; find & quot;, & quot; 1 & quot ;, & quot; PHP & quot;, & quot; regular & quot;, & quot; table & qu evaluate a PHP regular expression
For example, there is a line like, which is a PHP regular expression!
I want to save each word in an array, where an English word is saved as a unit,
For example, {"evaluate", "1", "PHP", "regular", "table", "da", "type", "like", "success ", "identifier", "identifier", "identifier "}


After finding a code segment on the Internet, you can store all the text in an array.

// Use regular expressions to match single half-width characters or single full-width characters and save them to the array $ ar
Preg_match_all ("/[\ x80-\ xff] +? \ X00/", $ str, $ ar );
$ Ar = $ ar [0];
// Remove the item with ASCII 0 characters from $ ar
For ($ I = 0; $ I <count ($ ar); $ I ++ ){
If ($ ar [$ I]! = Chr (0x00 )){
$ Ar_new [] = $ ar [$ I];
Echo "=". $ ar [$ I];
}
}

------ Solution --------------------
$ S = 'evaluate a PHP regular expression like, regular expression? Comment ';
Preg_match_all ("/[\ x80-\ xff]. | \ w +/", $ s, $ r );
Print_r ($ r [0]);

Array ([0] => evaluate [1] => 1 [2] => PHP [3] => positive [4] => then [5] => Table [6] => up to [7] => formula [8] => like [9] => limit [10] => limit [11] => limit)
------ Solution --------------------
This question involves Chinese and English word segmentation, right?
------ Solution --------------------
Is it "regular" or "positive", "then "? There is a big difference.
------ Solution --------------------
PHP code
  

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.