The preg_match() function in PHP is a commonly used function for executing regular expressions. Let me introduce the use of preg_match in detail.
Function usage
int preg_match_all ( string pattern, string subject, array matches [, int flags] )
Example 1
The code is as follows | Copy code | ||||||||
this is a test
",$out, PREG_SET_ORDER); This example will output: example: , example:
|
Extract domain name from URL
The code is as follows | Copy code |
// Get hostname from URL This example will output: domain name is: PPP. NET |
代码如下 | 复制代码 |
ini_set('pcre.backtrack_limit', 999999999); |
preg_match string length problem
The preg_match regular method extracts the target content. There are problems with life and death, and the code is tested to death.
Later I suspected that PHP's preg_match had a string length limit. Sure enough, I found that the value of "pcre.backtrack_limit" was only set to 100000 by default.
Solution:
代码如下 | 复制代码 |
ini_set('pcre.recursion_limit', 99999); |
Note: This parameter is available after PHP 5.2.0 version.
In addition, let’s talk about
http://www.bkjia.com/PHPjc/445283.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445283.htmlTechArticleThe preg_match() function in php is a commonly used function for executing regular expressions. Let me give Let’s introduce the use of preg_match in detail. Function usage int preg_match_all ( stri...