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