关于preg_match()函数的一点小说明
2017-01-14 18:28
309 查看
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
返回值:匹配到返回 int 1, 匹配不到返回 int 0 , 错误发生时,返回false.
例子:preg_match("[b]/[/b]php/i", "PHP is the web scripting language of choice.")
关于$pattern,定界符不一定要是 /,如 /string/。当要匹配的字符串里含有 / 时,就不能用 /作为定界符了,可以用@ #等等。如"@php@i"
例子:preg_match('[b]@[/b]^(?:http://)?([^/]+)@i',"http://www.php.net/index.html", $matches);
另外i表示不区分大小写,但是不支持g(其他语言里表示匹配全部),匹配全部用preg_match_all()。
返回值:匹配到返回 int 1, 匹配不到返回 int 0 , 错误发生时,返回false.
例子:preg_match("[b]/[/b]php/i", "PHP is the web scripting language of choice.")
关于$pattern,定界符不一定要是 /,如 /string/。当要匹配的字符串里含有 / 时,就不能用 /作为定界符了,可以用@ #等等。如"@php@i"
例子:preg_match('[b]@[/b]^(?:http://)?([^/]+)@i',"http://www.php.net/index.html", $matches);
另外i表示不区分大小写,但是不支持g(其他语言里表示匹配全部),匹配全部用preg_match_all()。
相关文章推荐
- Locust使用点滴
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supporte
- 健身饮食计划:增肌人群
- JAVA中几种文件操作流的效率对比
- 约瑟夫环
- Note04
- Linux 系统管理员 2017 年的 10 个新决心
- Caused by: java.lang.NumberFormatException: For input string: "[objectHTMLDivElement]"
- LDD之USB设备驱动
- sklearn——朴素贝叶斯文本分类
- 巧用ajax请求服务器加载数据列表时提示loading
- UE4 C++实现搜索指定目录下的指定类型的所有文件
- 【tcpdump】Linux抓包工具
- Kattis - Biased Standings
- Scala学习第四天
- 【C语言】模拟实现strcpy()、strncpy()函数
- PSR
- Mac 使用&技巧
- Dubbo+spring+springmvc+mybatis+Maven+Jetty+Mysql+Ajax多框架融合学习网址收藏
- Kattis -Bus Numbers