我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何在php中获取所有正则表达式匹配?

$pattern = '/b+[^\s-]*/';
$subject = 'brew and this is bunny';
preg_match($pattern, $subject, $matches);

Clearly, brew and bunny should match, but $matches only contains brew.

What should I do to have $matches contain all regex matches

You don't need the + after b in your regex.

$str = 'brew and this is bunny';
preg_match_all('/b[^\s]+/', $str, $matches);
print_r($matches);

Outputs

Array
(
    [0] => Array
        (
            [0] => brew
            [1] => bunny
        )
)

近期文章

  • 使用preg_match刮取html页面
  • PHP - require_once和类继承问题
  • 如何在数据库中存储这种值
  • 当ajax正在进行时,ajax显示加载图像
  • 我如何在PHP中每隔一分钟执行一次代码?
  • 在php中返回带有句点的顶级域名
  • 如何通过.htaccess配置本地构建的php作为CGI?
  • 基于数组数组内的EYE_SIZE以数字方式对数组进行排序
  • 我想通过点击编辑选择整行进行编辑
  • 验证码的替代品
  • 重新设计xt Commerce菜单
  • 需要帮助获取长字符串中特定单词后面的数字
  • 将HTML保存到数据库/ SQL中
  • 以Zend形式渲染无线电元素
  • CodeIgniter发送带图像的电子邮件
  • API请求无效 - “无效的IP”
  • mySQL时区转换
  • Symfony1提高了AJAX的动作速度
  • php foreach中的javascript加载器
  • 使用复选框值更新SQL数据库

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华