2

I'm working on my PHP to get the list of elements from each array.

Here is the output for the elements:

<?xml version='1.0' encoding='UTF-8' ?>
<tv generator-info-name="www.mysite.com/test">
<p id='links'>http://www.mysite.com/get-listing.php?channels=ABC FAMILY&id=101</p>
<p id='links'>http://www.mysite.com/get-listing.php?channels=CBS&id=102></p>
<p id='links'>http://www.mysite.com/get-listing.php?channels=CNN USA&id=103></p>
<p id='links'>http://www.mysite.com/get-listing.php?channels=ESPN USA&id=105></p>
<p id='links'>http://www.mysite.com/get-listing.php?channels=Fox News&id=106></p>
<p id='links'>http://www.mysite.com/get-listing.php?channels=Animal Planet&id=107></p>

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' ?>";
//echo $xml;
$xml .= '
<tv generator-info-name="www.testbox.elementfx.com/test">';
echo $xml;

foreach($html->find('p[id=links]') as $element)
{
  echo $element;
  //open each url 
}
?>

When I get the list of elements for each array, do you know how I can connect to each url using one element for each array using with simple_html_dom?

EDIT: When I tried this:

    foreach($html->find('p[id=links]') as $element)
    {
      //echo $element;
      //open each url
      $elementhtml = $element;
      // do something with $elementHtml
      //echo $elementhtml;
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $elementhtml);
      curl_setopt($ch, CURLOPT_HEADER, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      $result = curl_exec($ch);
      curl_close($ch);  
      echo $result;     
    }

It won't send request to each url. Any idea?

  • does anyone know how I can connect to each url in each array using with simple_html_dom? –  Apr 05 '14 at 16:15
  • What do you mean by connect? Do you want to send http requests to each url? – Andy Librian Apr 05 '14 at 19:49
  • @AndyLibrian yes of course I do. I want to send requests to each url by using simple_html_dom. How I can do that? –  Apr 05 '14 at 20:03

1 Answers1

0
foreach($html->find('p[id=links]') as $element)
{
  echo $element;
  //open each url 

  $elementHtml = file_get_html($element->innertext);

  // do something with $elementHtml
}
Andy Librian
  • 911
  • 5
  • 12
  • thank you very much for this, i have a problem with send request to each url. I'm getting an warning with file_get_contents. here is the warning: `Warning: file_get_contents('http://www.mysite.com/get-listing.php?channels=ABC FAMILY&id=101'>): failed to open stream: No such file or directory in /home/myusername/public_html/simple_html_dom.php on line 78`. Do you have any idea why i got the warning? –  Apr 06 '14 at 13:48
  • check out this link : http://stackoverflow.com/questions/3488425/php-ini-file-get-contents-external-url && http://stackoverflow.com/questions/8540800/php-how-can-use-curl-instead-file-get-contents – Andy Librian Apr 06 '14 at 13:55
  • I have tried it but it don't work. It won't let me to send request to each url. Do you know why? I have already put the `allow_url_fopen=1` in my php.ini. –  Apr 06 '14 at 14:31
  • Are you sure you have restarted the webserver after changing the php.ini? – Andy Librian Apr 06 '14 at 14:36
  • yes I did. Everything is working, but I guess my code must be wrong. Please see on my first post that I updated the code. –  Apr 06 '14 at 14:59
  • Try to change $elementhtml = $element; to $elementhtml = $element->innertext; – Andy Librian Apr 06 '14 at 15:46