正则表达式在php中获取div类的内容 [英] Regular Expression to get contents of div class in php

查看:639
本文介绍了正则表达式在php中获取div类的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆