Php 警告:file_get_contents()要求参数1为有效路径,数组为16

Php 警告:file_get_contents()要求参数1为有效路径,数组为16,php,simple-html-dom,Php,Simple Html Dom,我的脚本有问题,我试图连接到每个数组的每个url,但收到了警告。警告: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_g

我的脚本有问题,我试图连接到每个数组的每个url,但收到了警告。警告: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;
    }
  }
?>

我不知道你为什么要将URL保存在一个数组中,因为你似乎只想打开它们,但你可以更改它

$urls[] = $link->href;
$url = $urls;
进入这个

$urls[] = $url = $link->href;
编辑:请注意,通过使用$URL[]=。。。构造将某些内容附加到已存在的数组。可能您想做的是:

foreach ($links as $element) 
{
  //open each url in each array
  $urls = $link->href;
  foreach ($urls as $url) {
      $data = file_get_html($url);
      echo $data;
  }    
}

1$url=$url;2$URL是一个数组。只需将$link->href传递到文件\u get\u html即可。作为旁注,请不要将几个相同的警告消息复制粘贴到SO问题中-这不会增加任何内容。感谢您的建议,请您发布一个示例代码,我需要做哪些更改?@Antonion是的,我需要,我想一次在每个示例代码中打开它们。当我试图使用你发布的代码时,我仍然收到同样的警告。当我在这里获取元素时,如何连接到每个数组的每个url是我使用的代码://打开每个数组中的每个url$url[]=$url=$links->href$数据=文件\获取\ html$url;回波数据;您能发布var_dump$url;的结果吗@Antonion请看我的第一篇文章,我编辑了这篇文章,把var_dump$url的结果放进去@安东尼安,你看到结果了吗?
foreach ($links as $element) 
{
  //open each url in each array
  $urls = $link->href;
  foreach ($urls as $url) {
      $data = file_get_html($url);
      echo $data;
  }    
}