1 回答

TA貢獻1818條經驗 獲得超3個贊
在您的示例代碼中,您有
echo $x = $html->find('h2[class="section-heading"]',1)->outertext;
當您find()使用第二個參數(shù) 1 調用時,這只會返回 1 元素。相反,如果您找到所有這些-您可以對它們做任何您需要的事情...
$list = $html->find('h2[class="section-heading"]');
foreach ( $list as $item ) {
echo $item->outertext . PHP_EOL;
}
我剛剛測試的完整代碼是......
include(__DIR__."/simple_html_dom.php");
$html = file_get_html('http://campaignstudio.in/');
$list = $html->find('h2[class="section-heading"]');
foreach ( $list as $item ) {
echo $item->outertext . PHP_EOL;
}
這給出了輸出......
<h2 class="section-heading text-white">We've got what you need!</h2>
<h2 class="section-heading">At Your Service</h2>
<h2 class="section-heading">Let's Get In Touch!</h2>
- 1 回答
- 0 關注
- 104 瀏覽
添加回答
舉報