_only 发表于 2023-1-7 15:48:01

preg_match()函数和preg_match_all()函数

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) {=>string(2) "is" }
2
array(1) {=>array(2) {    =>    string(2) "is"    =>    string(2) "an"} }

nihaolai 发表于 2023-2-17 21:19:04

好好好好好好好好好好好好好好好好好顶
页: [1]
查看完整版本: preg_match()函数和preg_match_all()函数