2014-04-05 1 views
1

요소를 검색하기 위해 PHP를 사용하고 있습니다. <p id='links'>이라는 요소가 하나 있는데, simple_html_dom 메소드를 사용하여 get-listing.php라는 스크립트에서 contains를 파싱합니다. 나는 각 배열의 URL을 얻을 수있는 루프를 만들배열에서 요소를 가져 오는 방법

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

: 여기

<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> 

내 PHP 스크립트입니다 : 여기

는 GET-listing.php를에서 예제 출력 하나의 요소 id = links를 가진 get-listing.php.

내가 어떻게 할 수 있는지 말해 줄 수 있습니까?

답변

0

가정 simple_html_dom.php은 당신이 사용할 수 있어야 여기에 설명 http://simplehtmldom.sourceforge.net/로 데이터를 가져

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; 
    } 
} 
+0

대단히 감사합니다. 어떻게 각 배열에서 각 URL을 열 수 있습니까? –

+0

@ user3494862 죄송합니다. 그 의미가 확실하지 않습니다. – dops

+0

글쎄, 내가 URL리스트를 얻었을 때 나는 각 배열에 그것들 각각을 연결하기를 원한다. 예 : 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에 연결할 수 있습니까? –