|
preg_match()函数和preg_match_all()函数
<style type "text/css">
<!--
body,td,th {
font-size:12px;
}
body {
margin-left:12px;
margin-top:10px;
margin-right:10px;
margin-bottom:10px;
}
-->
</style></head>
<body>
<?php
$str = 'This is an example!';
$preg = '/\b\w{2}\b/';
$num1 = preg_match($preg,$str,$str1);
echo $num1.'<br>';
var_dump($str1);
$num2 = preg_match_all($preg,$str,$str2);
echo '<br>'.$num2.'<br>';
var_dump($str2);
?>
执行结果:
1
array(1) { [0]=> string(2) "is" }
2
array(1) { [0]=> array(2) { [0]=> string(2) "is" [1]=> string(2) "an" } }
|
|