是否可以解析外部网页的目录列表,因为该网页是可访问的,并且当我访问它时它会显示文件列表。我只想知道是否可以在 PHP 中动态解析文件以及如何解析? -谢谢
抱歉不清楚。我的意思是目录列表,例如:http://www.ibiblio.org/pub/ http://www.ibiblio.org/pub/(/.. 的索引)以及将内容读取为数组或在我的脚本中易于操作的内容的能力
您可以使用preg_match http://php.net/manual/en/function.preg-match.php or DomDocument http://php.net/manual/en/class.domdocument.php
对于你的情况:
$contents = file_get_contents("http://www.ibiblio.org/pub/");
preg_match_All("|href=[\"'](.*?)[\"']|", $contents, $hrefs);
var_dump($hrefs);
如果您想看一下工作演示 http://sandbox.phpcode.eu/g/15945.php.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)