douzi6992 2014-04-05 09:39
浏览 767
已采纳

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部