Detailed explanation of preg_match function [wei static charging]_PHP tutorial

WBOY
Release: 2016-07-13 17:53:55
Original
1022 people have browsed it

$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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478002.htmlTechArticle$str=sdfasfs12333ddd12233; preg_match(/ddd/si,$str,$arr);//Find three Continuous numbers echo pre; print_r($arr); echo /pre; 1. This function will only match the first matching value. 2. $arr[0...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template