使用file_get_contents()从特定div读取?

时间:2013-06-21 09:12:11

标签: php file-get-contents

我想从此页面中的div获取文本:

<html>
<head>Hello world!</head>
<body>
This is a test!<br>Hello man!<br>
    <div class="special">
    I want this text
    </div>
</body>
</html>

我使用此代码来获取没有任何标记的内容:

  

echo strip_tags(file_get_contents('http://website.com'));

但是,我只想从

获取内容
  

<div class="special">

来自该页面。这可能在PHP吗?

1 个答案:

答案 0 :(得分:0)

使用HTML解析器解析您使用file_get_contents()读取的对象。 This question列出了一堆可以使用的解析器