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

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题