Warning: file_get_contents() expects parameter 1 to be a valid path, array given 16

StackOverflow https://stackoverflow.com/questions/22884374

  •  28-06-2023
  •  | 
  •  

Pregunta

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"
¿Fue útil?

Solución

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;
  }    
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top