正则表达式在php中获取div类的内容 [英] Regular Expression to get contents of div class in php
问题描述
可能重复:
的语法
PHP DOMDocument,查找特定标签
有没有什么特殊的语法来获取嵌套div元素与唯一的类名在RegExp在PHP中。
考虑我有一个像
< div style =demo>
< div class =row>
< div title =abc@examples.comclass =text> ABC< / div>
< / div>
< div class =row>
< div title =pqr@examples.comclass =text> PQR< / div>
< / div>< / div>
这里我们如何使用RegExp和preg_match_all()来检索所有emailids。
解决方案
preg_match_all(/< div title = \(。*)\class = \ text \> /,$ subject,$ matches);
如果电子邮件是您想要的唯一数据,那么只有匹配电子邮件才会有更好的正则表达式。请参阅 http://fightingforalostcause.net/misc/2006/compare-email-regex .php
Possible Duplicate:
PHP DOMDocument, finding specific tags
How to parse and process HTML with PHP?Is there any special syntax to get nested div element with unique class name in RegExp in php. Consider I have a syntax like
<div style="demo"> <div class="row"> <div title="abc@examples.com" class="text">ABC</div> </div> <div class="row"> <div title="pqr@examples.com" class="text">PQR</div> </div></div>
here how can we retrieve all emailids using RegExp and preg_match_all().
解决方案preg_match_all("/<div title=\"(.*)\" class=\"text\">/", $subject, $matches);
If the emails is the only data you want there are better regexps for matching emails only. See http://fightingforalostcause.net/misc/2006/compare-email-regex.php
这篇关于正则表达式在php中获取div类的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!