【发布时间】:2015-12-18 08:23:11
【问题描述】:
我试图弄清楚如何返回数组(urls_array)中每个 url 的 file_contents。到目前为止,使用 simplehtmpdom 的以下代码只给了我一个结果,然后代码无法在 foreach 循环中运行。
$urlsall = 'http://php.net,
http://php.net/downloads,
http://php.net/docs.php,
http://php.net/get-involved,
http://php.net/support,
http://php.net/manual/en/getting-started.php,
http://php.net/manual/en/introduction.php,
http://php.net/manual/en/tutorial.php,
http://php.net/manual/en/langref.php,
http://php.net/manual/en/language.basic-syntax.php,
http://php.net/manual/en/language.types.php,
http://php.net/manual/en/language.variables.php,
http://php.net/manual/en/language.constants.php,
http://php.net/manual/en/language.expressions.php,
http://php.net/manual/en/language.operators.php,
http://php.net/manual/en/language.control-structures.php,
http://php.net/manual/en/language.functions.php,
http://php.net/manual/en/language.oop5.php,
http://php.net/manual/en/language.namespaces.php,
http://php.net/manual/en/language.errors.php,
http://php.net/manual/en/language.exceptions.php,
http://php.net/manual/en/language.generators.php,
http://php.net/manual/en/language.references.php,
http://php.net/manual/en/reserved.variables.php,
http://php.net/manual/en/reserved.exceptions.php,
http://php.net/manual/en/reserved.interfaces.php,
http://php.net/manual/en/context.php';
$urls_array = explode(',', $urlsall);
//var_dump ($urls_array);
foreach ($urls_array as $url)
{
$html = SimpleHtmlDom::file_get_html($url);
$title = $html->find('title',0);
echo $title->plaintext;
}
结果:PHP:超文本预处理器
ERROR: An error occured, The error has been reported.
Error on Dec 18, 2015 17:16PM - file_get_contents( http://php.net/downloads): failed to open stream: Invalid argument in E:\xampp\htdocs\sitename\SimpleHtmlDom.php on line 81
我想做的是从上面的 foreach 循环中获取所有 url 标题。
【问题讨论】:
-
网址标题到底是什么意思?可以举个例子吗?
-
你为什么要抓取 php 手册?
-
为什么要创建一个带有 url 的字符串,而不是预先声明数组?在逗号上爆炸不会修剪大多数 URL 现在将以新行开头的字符串。这就解释了为什么您在第二个 url 上遇到错误
-
@Sina ... 这个 url: 'php.net 当你得到 $title = $html->find('title',0) 时,它会给你页面标题: PHP: Hypertext预处理器
-
他的意思是那些url链接的html页面的标题。
标签: php arrays url file-get-contents simple-html-dom