0
我想从网站中提取下载链接。不过,我只获得我阵列中的最后一项。foreach中foreach只回声最后一项?
<?php
require 'functions/simple_html_dom.php';
$html = new simple_html_dom();
$html->load_file('http://www.nyaa.eu/?page=torrents&user=64513');
$page_title = $html->find('title',0);
?>
Title:<?php echo $page_title->plaintext; ?><br><br>
Links:<br>
<?php
foreach($html->find('td.tlistdownload a') as $links){
$dllinks[] = $links->href;
}
foreach($html->find('td.tlistname a') as $names){
echo '<a href="';
foreach ($dllinks as $value)
{
echo $value;
}
echo '">' . $names->innertext . '</a><br>';
}
foreach ($dllinks as $value)
{
echo $value . '<br>';
}
?>
当我使用var_dump时,它显示了我的数组中的所有下载链接。但由于一些奇怪的原因,它只显示了第二个foreach循环中的最后一项。
编辑:
对不起它应该是这样的
<?php
require 'functions/simple_html_dom.php';
$html = new simple_html_dom();
$html->load_file('http://www.nyaa.eu/?page=torrents&user=64513');
$page_title = $html->find('title',0);
?>
Title:<?php echo $page_title->plaintext; ?><br><br>
Links:<br>
<?php
foreach($html->find('td.tlistdownload a') as $links){
$dllinks[] = $links->href;
}
foreach($html->find('td.tlistname a') as $names){
echo '<a href="';
foreach ($dllinks as $value)
{
echo $value;
}
echo '">' . $names->innertext . '</a><br>';
}
?>
你确定要将整个'$ dllinks'数组'echo'到链接'href'吗? – MISJHA 2013-05-10 17:31:59
我同意,我不认为你的代码做你认为它确实... – Stephen 2013-05-10 17:37:18