douzi6992 2014-04-05 17:39
浏览 761
已采纳

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

I have got a problem with my script, I'm trying to connect to each url for each array, but I got the warnings. 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

Here is the line 78 for simple_html_dom.php:

$contents = file_get_contents($url, $use_include_path, $context, $offset);

Here is the output:

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

Here is the 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;
    }
  }
?>

Can you please tell me how i can connect to each url for each array when I get the list of urls from get-listing.php using with simple_html_dom?

EDIT: Here is the result:

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"
  • 写回答

1条回答 默认 最新

  • doufu8127 2014-04-05 17:46
    关注

    I don't know exactly why are you saving the urls in an array since seems you want to simply open them but you can change this

    $urls[] = $link->href;
    $url = $urls;
    

    into this

    $urls[] = $url = $link->href;
    

    EDIT: Mind that by using the $urls[] = ... construct you are appending something to an already existing array. Probably what you wanted to do was the following:

    foreach ($links as $element) 
    {
      //open each url in each array
      $urls = $link->href;
      foreach ($urls as $url) {
          $data = file_get_html($url);
          echo $data;
      }    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化