您好我想使用simple_html_dom文本(网站)集群项目,但我遇到了一个奇怪的问题。当我在外部循环中使用echo时,url和片段就是你所期望的,但是当我尝试回显数组内容时,我已经收集到了循环外部的url,但片段不见了,最后一个片段在他们的位置。PHP奇怪的问题与file_get_html
<?php
// create HTML DOM
include("simple_html_dom.php");
$search_query = 'something';
$j = 1;
$k = 1;
/*************************GOOGLE***************************/
for ($i = 0; $i < 1; $i++) {
$url = sprintf('http://www.google.com/search?q=%s&start=%d', $search_query, 10 * $i);
$html = file_get_html($url);
foreach ($html->find('a[class=l]') as $element) {
$urls[$j] = $element->href;
echo $element->href . "\n\n\n\n\n";
$j++;
}
foreach ($html->find('div[class=s]') as $element) {
$snippets[$k] = $element->innertext;
echo $element->innertext . "\n\n\n\n\n";
$k++;
}
}
$j = 1;
foreach ($snippets as $elemement) {
echo $urls[$j] . "\n" . $element . "\n\n\n\n";
$j++;
}
?>
请在下次发布可读代码,您可以使用http://www.phpformatter.com/。 – Lekensteyn 2010-11-06 15:25:07