1

我正在努力获取已解析 HTML 的所有节点,因为我正在使用 Simple HTML DOM Parser 我能够使用此获取所有 div 或所有 span 标签

foreach($html->find("div") as $e)
{
   //here I got all div tags which are contained in html object but I want all tags not divs
   //then I am addin coustom attribute like this way
  $e->setattribute("My_id","abc");
}

任何帮助将不胜感激。

4

1 回答 1

0

为此,我刚刚添加了 phpquery 库。

$doc = phpQuery::newDocument($html);
$ul = pq('*');
$i = 1;
foreach($ul as $li) {
   pq($li)->attr('sws_id', $i);
    $i++;
}

要安装 phpQuery,您可以通过 git 按照此 url 找到此库。

https://github.com/rrmodi88/phpQuery

于 2013-03-13T05:49:18.683 回答