Home > Backend Development > PHP Tutorial > 正则表达式 - 一句php解析html页面的脚本问题

正则表达式 - 一句php解析html页面的脚本问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:48:34
Original
1173 people have browsed it

preg_match_all('/<td width="20%" align="left">.*<\/td>/u',$html,$match,PREG_OFFSET_CAPTURE);
Copy after login
Copy after login

主要是其中的正则表达式没看明白,开头的/和结尾的/u是代表其中的内容是unicode么?不需要用\转译这两个/

然后PREG_OFFSET_CAPTURE这个flag到底又什么用,看了文档还是没怎么明白,希望各位大大指教

回复内容:

preg_match_all('/<td width="20%" align="left">.*<\/td>/u',$html,$match,PREG_OFFSET_CAPTURE);
Copy after login
Copy after login

主要是其中的正则表达式没看明白,开头的/和结尾的/u是代表其中的内容是unicode么?不需要用\转译这两个/

然后PREG_OFFSET_CAPTURE这个flag到底又什么用,看了文档还是没怎么明白,希望各位大大指教

/ / 是表示中间内容是表达式。 u 是修饰符,定义这个模式字符串被认为是utf-8的。

http://www.php.net/manual/zh/reference.pcre.pattern.modifiers.php

嗯,//标示正则表达式开始结束,u是修饰符,具体可见 http://www.php.net/manual/zh/reference.pcre.pattern.modifiers.php

Flag结果排序方式,结合实际测试可以更清楚。

PREGPATTERNORDER 结果排序为$matches[0]保存完整的所有匹配, $matches[1] 保存第一个()的所有匹配,以此类推

PREGSETORDER 结果排序为$matches[0]包含第一次匹配得到的所有匹配(包含子组), $matches[1]是包含第二次匹配到的所有匹配(包含子组)的数组,以此类推。

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template