Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用file_get_contents()读取特定div?_Php_File Get Contents - Fatal编程技术网

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

Php 使用file_get_contents()读取特定div?,php,file-get-contents,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> 你好,世界! 这是一个考验

我想从该页的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>

你好,世界!
这是一个考验<你好,伙计
我想要这个文本
我使用此代码获取内容,而不带任何标记:

回音条标签(文件获取内容(“”))

但是,我只想从


从那一页。这在PHP中是可能的吗?

使用HTML解析器解析您使用
file\u get\u contents()
读取的对象。列出了一组可以使用的解析器

如果可以,请使用HTML解析器。现在去搜索吧,有很多这样的例子。应该有几十个这样的副本,以上只是我第一次发现。使用
DOMDocument
DOMXPath
。如何使用?我看到了这些主题,但它们太难理解了。@JohnBalls:太难了?基本的例子有5行。但是你需要阅读手册,问题是我是葡萄牙人,我已经13岁了