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