Below we give a PHP regular expression matching string in the specified tag implementation program code, there is a need to learn friends can refer to this tutorial.
In PHP applications, regular expressions are mainly used to:
• Regular match: matches the corresponding content according to the regular expression
• Regular substitution: matches content according to regular expression and replaces
• Regular segmentation: Splitting strings based on regular expressions
Common
Preg_match_all ()
The Preg_match_all () function is used to perform a regular expression global match, which returns the number of times the entire pattern match succeeds (possibly 0), and returns FALSE if an error occurs.
Grammar:
int Preg_match_all (string pattern, string subject, array matches [, int flags])
Instance
$STR = "The two broad of the Gan Jia Kou East # label # 2 #标签3. #标签4, all hair $1234¥XC,CVM, ¥12,dflksjf How to # tags 5.x
The code is as follows |
Copy Code |
#tag6. CVXCV ""; Preg_match_all ('/# ([a-za-z0-9x7f-xff]+)/', $STR, $mat); Print_r ($mat);
Preg_match ("/[x{00a5}x{ffe5}" (d+)/U ", $str, $mat); Print_r ($mat); |
Regular matching Chinese characters are slightly different depending on the page encoding:
gbk/gb2312 Code: [x80-xff>]+ or [xa1-xff]+
utf-8 code: [x{4e00}-x{9fa5}]+/u
Example:
The code is as follows |
Copy Code |
$STR = "Learning php is a happy thing. "; Preg_match_all ("/[x80-xff]+/", $str, $match); UTF-8 using: Preg_match_all ("/[x{4e00}-x{9fa5}]+/u", $str, $match); Print_r ($match); ?> |
Additional notes:
Double-byte character encoding range
1. GBK (gb2312/gb18030)
X00-xff GBK Double byte encoding range
x20-x7f ASCII
Xa1-xff Chinese gb2312
X80-xff Chinese GBK
2. UTF-8 (Unicode)
U4E00-U9FA5 (English)
x3130-x318f (Korean
XAC00-XD7A3 (Korean)
u0800-u4e00 (Japanese)
http://www.bkjia.com/PHPjc/631584.html www.bkjia.com true http://www.bkjia.com/PHPjc/631584.html techarticle below we give a PHP regular expression matching string in the specified tag implementation program code, there is a need to learn friends can refer to this tutorial. In PHP applications, regular expressions are mainly ...