最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP preg_match正则表达式的使用
时间:2022-06-24 20:01:26 编辑:袖梨 来源:一聚教程网
函数用法
int preg_match_all ( string pattern, string subject, array matches [, int flags] )
例1
| 代码如下 | 复制代码 |
|
preg_match_all ("|]+>(.*)[^>]+>|U","example: this is a test ",$out, PREG_SET_ORDER);print $out[0][0].", ".$out[0][1]."n"; print $out[1][0].", ".$out[1][1]."n"; ?> 本例将输出: this is a test , this is a test
|
|
例2
URL 中取出域名
| 代码如下 | 复制代码 |
|
// 从 URL 中取得主机名 本例将输出: domain name is: PPP.NET |
|
preg_match字符串长度问题
preg_match正则提取目标内容,死活有问题,代码测得死去活来。
后来怀疑PHP 的preg_match有字符串长度限制,果然,发现“pcre.backtrack_limit ”的值默认只设了100000。
解决办法:
| 代码如下 | 复制代码 |
| ini_set('pcre.backtrack_limit', 999999999); | |
注:这个参数在php 5.2.0版本之后可用。
另外说说关于:pcre.recursion_limit
pcre.recursion_limit是PCRE的递归限制,这个项如果设很大的值,会消耗所有进程的可用堆栈,最后导致PHP崩溃。
也可以通过修改配置来限制:
| 代码如下 | 复制代码 |
| ini_set('pcre.recursion_limit', 99999); | |
实际项目应用中,最好也对内存进行限定设置:ini_set('memory_limit', '64M'); , 这样就比较稳妥妥嘎。
相关文章
- 拷贝漫画官方版下载-拷贝漫画最新版下载入口 12-18
- yandex入口引擎最新可用地址发布-yandex入口引擎安全稳定登录技巧 12-18
- 《喵次元》官网入口-直达链接 12-18
- 四六级成绩查询官方入口-中国教育考试网四六级成绩查询通道 12-18
- 2925邮箱官方入口网址直达-2925邮箱一键登录官网 12-18
- 163免费邮箱官网登录入口-163免费邮箱多账号快捷登录入口 12-18