我的脚本有问题,我试图连接到每个阵列的每个网址,但是我收到了警告。警告:file_get_contents()期望参数1是一个有效的路径,给出的数组:在第78行的/home/myusername/public_html/simple_html_dom.php中
这是simple_html_dom.php的第78行:
$contents = file_get_contents($url, $use_include_path, $context, $offset);
这是输出:
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/ytestbox/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
Warning: file_get_contents() expects parameter 1 to be a valid path, array given in /home/myusername/public_html/simple_html_dom.php on line 78
这是PHP:
<?php
ini_set('max_execution_time', 300);
$errmsg_arr = array();
$errflag = false;
$link;
include ('simple_html_dom.php');
$base1 = "http://www.mysite.com/get-listing.php";
$html = file_get_html($base1);
$xml .= "<?xml version='1.0' encoding='UTF-8' ?>";
$xml .= '
<tv generator-info-name="www.testbox.elementfx.com/test">';
echo $xml;
$links = $html->find('p[id=links] a');
foreach ($links as $element)
{
//open each url in each array
$urls[] = $link->href;
$url = $urls;
$data = file_get_html($url);
echo $data;
}
}
?>
当我使用simple_html_dom从get-listing.php获取网址列表时,你能告诉我如何连接到每个数组的每个网址吗?
编辑:结果如下:
string(72) "http://www.mysite.com/get-listing.php?channels=ABC FAMILY&id=101"
string(65) "http://www.mysite.com/get-listing.php?channels=CBS&id=102"
string(69) "http://www.mysite.com/get-listing.php?channels=CNN USA&id=103"
string(70) "http://www.mysite.com/get-listing.php?channels=ESPN USA&id=105"
string(70) "http://www.mysite.com/get-listing.php?channels=Fox News&id=106"
string(75) "http://www.mysite.com/get-listing.php?channels=Animal Planet&id=107"
string(73) "http://www.mysite.com/get-listing.php?channels=USA Network&id=108"
string(67) "http://www.mysite.com/get-listing.php?channels=SPIKE&id=110"
string(71) "http://www.mysite.com/get-listing.php?channels=BRAVO USA&id=111"
string(68) "http://www.mysite.com/get-listing.php?channels=BRAVO1&id=112"
string(68) "http://www.mysite.com/get-listing.php?channels=BRAVO2&id=113"
string(68) "http://www.mysite.com/get-listing.php?channels=BRAVO3&id=114"
string(68) "http://www.mysite.com/get-listing.php?channels=BRAVO4&id=115"
string(68) "http://www.mysite.com/get-listing.php?channels=BRAVO5&id=116"
string(68) "http://www.mysite.com/get-listing.php?channels=BRAVO6&id=117"
string(68) "http://www.mysite.com/get-listing.php?channels=BRAVO7&id=118"
答案 0 :(得分:0)
我不确切地知道为什么要将数据库保存在数组中,因为您似乎只想打开它们但是可以更改此
$urls[] = $link->href;
$url = $urls;
进入这个
$urls[] = $url = $link->href;
编辑:请注意,通过使用$urls[] = ...
构造,您将向已经存在的数组添加内容。您可能想要做的是以下内容:
foreach ($links as $element)
{
//open each url in each array
$urls = $link->href;
foreach ($urls as $url) {
$data = file_get_html($url);
echo $data;
}
}