【发布时间】:2016-04-09 18:58:16
【问题描述】:
我正在尝试使用正则表达式 preg_match_all 与 class 标签 匹配来获取特定的 HTML 代码部分,但它返回的是空数组。
这是我想从完整的 HTML
中获取的 html 部分<div class="details">
<div class="title">
<a href="citation.cfm?id=2892225&CFID=598850954&CFTOKEN=15595705"
target="_self">Restrictification of function arguments</a>
</div>
</div>
我在哪里使用这个 regex
preg_match_all('~<div class=\'details\'>\s*(<div.*?</div>\s*)?(.*?)</div>~is', $html, $matches );
注意: $html 变量包含我要搜索的整个 html。
谢谢。
【问题讨论】:
-
可能是因为你在\'details\'处使用了错误的引号(-> \"details\" or ["']details["'])
-
输出应该是什么(在你的例子中)?
-
第一次使用正则表达式,我认为它应该给出内的内容。我不知道它将如何返回输出。在“title” div 或“details” div 内?