最新下载
热门教程
- 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'); , 这样就比较稳妥妥嘎。
相关文章
- 歪歪漫画免费版入口在哪-2026最新网页版地址链接与网址分享 04-30
- 如何更换搜狗拼音输入法皮肤 04-30
- Deepseek极速下载-Deepseek中文版下载 04-30
- 蚂蚁新村2026年4月29日题目答案 04-30
- 夸克网盘怎么设置开机自启动 04-30
- 《Resident Evil Requiem》中有一个我们可能永远也见不到的完整章节 04-30