Php 如何获取数组中的元素

Php 如何获取数组中的元素,php,simple-html-dom,Php,Simple Html Dom,我正在用PHP搜索元素。有一个元素名为,我使用简单的\u html\u dom方法来解析脚本get-listing.php中的内容 下面是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'>h

我正在用PHP搜索元素。有一个元素名为
,我使用简单的\u html\u dom方法来解析脚本get-listing.php中的内容

下面是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>

101 ABC系列

102哥伦比亚广播公司

美国有线电视新闻网103频道

105 ESPN美国

106福克斯新闻

动物星球

108美国网络

以下是我的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);   

$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">';
?>

我想创建循环,从get-listing.php获取每个数组中的url,其中一个元素id=links


你能告诉我怎么做吗?

假设simple\u html\u dom.php获得了这里描述的数据,那么你应该能够使用

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;
}
编辑

如果您想对HREF进行排序,可以在这里进行一些简单的测试

foreach ($links as $link) {
  //Get raw URL's here
  if (strstr($link->href,'get_listing')) {
     $listings[] = $link->href;
  } else {
     $general[] = $link->href;
  }
} 

非常感谢您,您知道我如何打开每个数组中的每个url吗?@user3494862对不起,我不知道您的意思,您能帮我解释一下吗?我的意思是,当我得到url列表时,我想连接每个数组中的每个url。e、 g:我连接到get-listing.php,我连接到
http://testbox.elementfx.com/get-listing.php?channels=ABC%20FAMILY&id=101
http://testbox.elementfx.com/get-listing.php?channels=CBS&id=102
http://testbox.elementfx.com/get-listing.php?channels=CNN%20USA&id=103
等等。当我获得url列表时,如何连接到每个数组的每个url?我将使用$listingsArray=array_walk($fruits,'extractURLType','get_listing')遍历数组以查找匹配项;并定义一个函数extractURLType($data,$key,$text),将$text与$data匹配,请参见此处的手动输入,已经有匹配项,但我需要向每个url发送请求以获取响应。您知道如何向每个url发送请求以获取每个响应中的元素列表吗?