今下午帮一哥们写了这段代码,在foreach之前没对$matches[0]做过什么操作,打印或者var_dump()都是正常,但是foreach不知为什么指针就在最后一个元素了,而且reset()之后也不行,求解!
$str=iconv('gb2312','utf-8',file_get_contents('http://www.newegg.com.cn/CategoryList.htm'));
preg_match_all("#<h2><a href='http://www.newegg.com.cn/Category/(\d+)\.htm' title='([^']+)[\S\s]+?</ul>#i",$str,$matches);
//print_R(array_combine($matches[1],$matches[2]));
echo '<br>';
//reset($matches[0]);
//while(list($key,$val)=each($matches[0]))
foreach($matches[0] as $val);
{
//echo $matches[2][$key].'<br>';
preg_match_all("#<a href='http://www\.newegg\.com\.cn/SubCategory/(\d+)\.htm' title='([^']+)#i",$val,$match);
print_R(array_combine($match[1],$match[2]));
echo '<br>';
}