【问题标题】:How to extract contents of a div from a string using regx [duplicate]如何使用正则表达式从字符串中提取 div 的内容 [重复]
【发布时间】:2011-12-16 06:51:09
【问题描述】:

可能重复:
regex php: find everything in div

我有类似的字符串

$str= 'hello asd asd 
<div class="name">Sunil</div>' asdasd
asdasdasd
asdasdasdasd;

我想获取 div name 的内容。 (意味着我想得到 Sunil )使用 reg ex..

请帮帮我。

【问题讨论】:

  • 这不是 PHP 字符串..(替换引号)
  • 如果div 的内容可能包含标记(与其他div 一样),那么就不可能使用正则表达式。是这种情况还是内容总是没有标记的文本?此外,您的代码看起来无效。

标签: php regex


【解决方案1】:

您不能使用正则表达式进行递归搜索,因为它无法表达递归。这就是人们编写解析器的原因。

我相信你要找的是http://simplehtmldom.sourceforge.net/

【讨论】:

  • 有递归正则表达式。这不是一个合理的努力(并以欺骗方式回答)。如果与问题标签不匹配,也请发表评论。
猜你喜欢
  • 1970-01-01
  • 2011-08-25
  • 1970-01-01
  • 2020-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-30
  • 2014-10-17
相关资源
最近更新 更多