Pergunta

I'm working on my PHP to search for the elements. There are are one element called <p id='links'>, I use simple_html_dom method to parsing the contains from my script called get-listing.php.

Here is the example output from get-listing.php:

<p id='channels'>101 ABC FAMILY</p>
<p id='links'>
    <a href='http://www.mysite.com/get-listing.php?channels=ABC FAMILY&id=101'>http://www.mysite.com/get-listing.php?channels=ABC FAMILY&id=101</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>102 CBS</p>
<p id='links'>
    <a href='http://www.mysite.com/get-listing.php?channels=CBS&id=102'>http://www.mysite.com/get-listing.php?channels=CBS&id=102</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>103 CNN USA</p>
<p id='links'>
    <a href='http://www.mysite.com/get-listing.php?channels=CNN USA&id=103'>http://www.mysite.com/get-listing.php?channels=CNN USA&id=103</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>105 ESPN USA</p>
<p id='links'>
    <a href='http://www.mysite.com/get-listing.php?channels=ESPN USA&id=105'>http://www.mysite.com/get-listing.php?channels=ESPN USA&id=105</a>
</p>
<a id="aTest" href="rtmp://$OPT:rtmp-raw=rtmp://ny.iguide.to/edge playpath=49f5xnbs2wra0ut swfUrl=http://player.ilive.to/player_ilive_2.swf pageUrl=http://www.ilive.to token=UYDk93k#09sdafjJDHJKAD873">Stream 1</a>
<p id='channels'>106 FOX News</p>
<p id='links'>
    <a href='http://www.mysite.com/get-listing.php?channels=FOX News&id=106'>http://www.mysite.com/get-listing.php?channels=FOX News&id=106</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>107 Animal Planet</p>
<p id='links'>
    <a href='http://www.mysite.com/get-listing.php?channels=Animal Planet&id=107'>http://www.mysite.com/get-listing.php?channels=Animal Planet&id=107</a>
</p>
<a id="aTest" href="">Stream 1</a>
<p id='channels'>108 USA Network</p>
<p id='links'>
    <a href='http://www.mysite.com/get-listing.php?channels=USA Network&id=108'>http://www.mysite.com/get-listing.php?channels=USA Network&id=108</a>
</p>
<a id="aTest" href="">Stream 1</a>

Here is my PHP script:

<?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);   

$countp = $html->find('p');     
header("Content-type: text/xml");
$xml .= "<?xml version='1.0' encoding='UTF-8' ?>";
//echo $xml;
$xml .= '<tv generator-info-name="www.testbox.elementfx.com/xmltv">';
?>

I want to create the loops to get the url in each array from get-listing.php with one element id=links.

Can you please tell me how I can do that?

Foi útil?

Solução

Assuming simple_html_dom.php gets your data as described here http://simplehtmldom.sourceforge.net/ then you should be able to use

foreach to go through the results

$links = $html->find('p[id=links] a');
foreach ($links as $link) {
     //Get raw URL's here
     $urls[] = $link->href;
}

EDIT

if you want to sort through the hrefs you could do a few simple tests here

foreach ($links as $link) {
  //Get raw URL's here
  if (strstr($link->href,'get_listing')) {
     $listings[] = $link->href;
  } else {
     $general[] = $link->href;
  }
} 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top