hrefspace

 找回密码
 立即注册
搜索
热搜: PHP PS 程序设计
查看: 501|回复: 1

preg_match()函数和preg_match_all()函数

[复制链接]

926

主题

1137

帖子

3586

积分

超级版主

Rank: 8Rank: 8

积分
3586

论坛头条论坛元老谋士数据帝优秀版主超级版主见习版主论坛版主

发表于 2023-1-7 15:48:01 | 显示全部楼层 |阅读模式
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"  } }
世界上最遥远的距离,不是生与死的距离,而是我站在你面前,你却不知道我爱你
回复

使用道具 举报

0

主题

113

帖子

236

积分

京兆尹

Rank: 3Rank: 3

积分
236
发表于 2023-2-17 21:19:04 | 显示全部楼层
好好好好好好好好好好好好好好好好好顶
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|hrefspace

GMT+8, 2024-5-2 19:57 , Processed in 0.059264 second(s), 22 queries .

Powered by hrefspace X3.4 Licensed

Copyright © 2022, hrefspace.

快速回复 返回顶部 返回列表