您当前的位置: 首页 >  php

彭世瑜

暂无认证

  • 0浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

PHP 正则表达式preg_match

彭世瑜 发布时间:2020-02-05 14:00:32 ,浏览量:0

简化定义

preg_match (string $pattern , string $subject [array &$matches] ) : int

说明: $pattern 搜索模式 $subject 字符串 $matches 搜索结果(可选)

界定符:/

示例

// 只校验结果
echo preg_match('/\d+/', '1234');
// 1


// 获取匹配结果
if(preg_match('/age=(\d+)/', 'age=16', $matches)){
    var_dump($matches);
}
/**
array(2) {
    [0]=> string(6) "age=16"
    [1]=> string(2) "16"
  }
*/

参考 PHP 正则表达式 https://www.php.net/manual/zh/function.preg-match.php

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.1389s