Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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\u get\u html循环浏览文件夹的内容?_Php_Loops - Fatal编程技术网

Php 使用file\u get\u html循环浏览文件夹的内容?

Php 使用file\u get\u html循环浏览文件夹的内容?,php,loops,Php,Loops,是否可以对每个文件使用file\u get\u html循环浏览文件夹 我目前正在使用以下工具: $html = file_get_html('http://example.local/folder/file1.html'); 是否可以设置文件夹的路径,然后在文件夹内容中循环 $html = file_get_html('http://example.local/folder/'); 文件夹中的文件可以命名为任何名称(没有设置命名约定!),但它们始终是html文件 我正在使用它来获取HTML

是否可以对每个文件使用
file\u get\u html
循环浏览文件夹

我目前正在使用以下工具:

$html = file_get_html('http://example.local/folder/file1.html');
是否可以设置文件夹的路径,然后在文件夹内容中循环

$html = file_get_html('http://example.local/folder/');
文件夹中的文件可以命名为任何名称(没有设置命名约定!),但它们始终是html文件


我正在使用它来获取HTML。

这将是一般的想法:

$source = '/some/local/folder/';
foreach (new DirectoryIterator($source) as $fileInfo) {
    if($fileInfo->isDot()) continue;
    $html = file_get_contents($source.$fileInfo->getFilename());
    //do stuff with $html
}

这是可能的,但不是那样的。我认为您需要查看手册,以了解远程http://folders不可能实现的功能。@wroniasty如果这有什么不同,它是一个本地站点。PHP在标准库中没有
file\u get\u html()
函数。你是说
file\u get\u contents()
,还是这个函数是在你的应用程序中定义的?@duskwuff很抱歉,我应该说我使用的是simple\u html\u dom.php库。这个库可以使用吗?只要用你读取文件内容的任何方法替换
file\u get\u contents