Home >Backend Development >PHP Tutorial >Detailed explanation of preg_match function [wei static charging]_PHP tutorial
$str='sdfasfs12333ddd12233';
preg_match('/ddd/si',$str,$arr);//Find three consecutive numbers
echo '
';</p> <p>print_r($arr);</p> <p>echo '';
1. This function will only match the first matching value.
2. $arr[0] stores the result.
preg_match_all all results, so it is a two-dimensional array: $arr[0][1] stores the first result, $arr[0][n] stores the nth result;
$arr[1][0] stores the result of the first subexpression in the first result, $arr[1][n] stores the first subexpression in the n+1th result The result of the expression;
Example: When wei is static, the most commonly used knowledge points
$str="111-555-666 dfs5+fsfffsd-2215affsfsdf";
preg_match('/(d)1{2}-(d)2{2}-(d)3{2}/si',$str,$arr);//Must use ', cannot be used ", because there is reverse capture
Second: http://localhost/wc.php/15,23,45.html processing method:
Method 1, use regular table processing in php; $_SERVER[PATH_INFO];
$para=$_SERVER['PATH_INFO'];
$pattern='/(d)+/si';//There is a number
$pattern='//(d+),(d+),(d+).html$/si';
preg_match($pattern,$para,$arr);
Method 2, use apache rewrite.