2013-03-28 70 views
0

我曾使用SIMPLE HTML DOM來捕獲三個不同的元素。我想逐個顯示它。但是它顯示了使用for循環時的錯誤消息:SimpleHTML循環返回未定義索引

未定義的索引:i。

這是怎麼回事?請幫幫我。

include('simple_html_dom.php'); 

$html = file_get_html('http://....'); 

$a=$html->find('div.briefimage'); 
echo $a[0]; 

$b = $html->find('span.briefcitTitle'); 
echo $b[15]; 
$c = $html->find('table.bibItems td'); 
echo $c[0]; 

for ($i = 0; $i <= 10; ++$i) { 
    echo $a[i]->plaintext . '<br>'; 
    echo $b[i]->outertext . '<br>'; 
    for ($j = i; $i <= 2; $j++) { 
    echo $c[i]->innertext . '<br>'; 
    } 
} 

回答

0

之前通過垂耳檢查每個數組是否set.Or嘗試使用isset檢查whther陣列迭代是set.Also的print_r()或var_dumb您的陣列來檢查您是否在array.You是獲取值得到通知是因爲你的數組中沒有包含值。

1

你應該使用$i,而不是僅僅i ...所以改變

for ($i = 0; $i <= 10; ++$i) { 
    echo $a[i]->plaintext . '<br>'; 
    echo $b[i]->outertext . '<br>'; 
    for ($j = i; $i <= 2; $j++) { 
    echo $c[i]->innertext . '<br>'; 
    } 
} 

0

這意味着你的陣列中的一個$a$b$c缺少你的關鍵正在嘗試訪問$i

$foo = array('a', 'b'); 
$i = 3; 
echo $foo[$i]; # Error because there is no third key in $foo 
0

只是採取了快速瀏覽一下,嘗試$i++而不是++$i

如果不工作的var_dump $ A,$ B & $ C