如何在php中获取div内容 [英] How can I get a div content in php

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

问题描述

我在php(string)中有一个div,我想获取内容.

I have a div in php(string) and I want to get the content.

例如:

<div id="product_list" style="width:100%; float:none;">
      <div>
       bla bla bla
      </div>
      bla bla          
</div>

我想要

<div>
     bla bla bla
</div>
     bla bla

样式正在改变,我只知道div ID.

The style is changing, I know only the div id.

已更新

这是我的代码,与turbod源相同,结果也相同.

this is my code, same as turbod source and the results are the same too.

所以这是原始的 html

$doc = new DOMDocument();
$doc->loadHTML($buffer);
$id = $doc->getElementById('product_list')

在此代码之后,我得到以下信息:链接

And after this code I get the following: link

推荐答案

使用php DomDocument类. http://www.php.net/manual/zh/class.domdocument.php

Use the php DomDocument class. http://www.php.net/manual/en/class.domdocument.php

$dom = new DOMDocument();

$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
$divContent = $xpath->query('//div[id="product_list"]');

这篇关于如何在php中获取div内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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