PHP, like JavaScript, regular matching content is usually used//wrapped up, you can use other non-letters and numbers to play the same role, can not use \ \ \
$preg = '/demo/';
Preg_match
$str = "abcdefgabcdbc"; $pattern = '/[da]bc/'; echo'preg_match:'.preg_match($pattern, $str).'
'; echo'preg_match_all:'.preg_match_all($pattern, $str,$matches).'
'; //preg_match_all匹配所有,并将其匹配项带入第三个参数 $matches var_dump($matches); ?>//preg_match:1preg_match_all:3array(1) { [0]=> array(3) { [0]=> string(3) "abc" [1]=> string(3) "abc" [2]=> string(3) "dbc" } }
Preg_replace
$str = '2014-11-25'; //使用()包括起来代表一个单元,可以与${n}对应使用,匹配的第几个内容会带入对应的${n}$preg = '/(-)/'; $temp = 'Year'; echo preg_replace($preg,$temp.'${1}',$str); echo'
'; $preg = array( '/(\d+)/' ); $temp = array( 'temp[${1}]' ); echo preg_replace($preg,$temp,$str);?>//2014Year-11Year-25temp[2014]-temp[11]-temp[25]
Preg_split
$str = '1+2-3/4*5';$pattern = '#[+-/*]#';$res = preg_split($pattern,$str);print_r($res);//Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the PHP regular function, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.