【发布时间】:2014-05-17 23:11:04
【问题描述】:
我正在使用我的 PHP 来获取每个数组中的元素列表。
这是元素的输出:
<?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>
这里是 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
}
?>
当我得到每个数组的元素列表时,你知道如何使用 simple_html_dom 为每个数组使用一个元素连接到每个 url?
编辑:当我尝试这个时:
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;
}
它不会向每个 url 发送请求。有什么想法吗?
【问题讨论】:
-
有谁知道我如何使用 simple_html_dom 连接到每个数组中的每个 url?
-
连接是什么意思?是否要向每个 url 发送 http 请求?
-
@AndyLibrian 是的,我当然愿意。我想使用 simple_html_dom 向每个 url 发送请求。我该怎么做?