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

警告: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;
      }    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!