我有cURL和Simple Html Dom Parser的代码:
$ch = curl_init ("");
$query="Electrician+in+".$_GET['city_name'] (this variable = Moscow (for example));
curl_setopt ($ch, CURLOPT_URL, "http://www.google.com/search?q=".$query);
echo "http://www.google.com/search?q=".$query;
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$output = curl_exec ($ch);
curl_close($ch);
$html = new simple_html_dom();
$html->load($output, true, false);
$k = 0;
foreach ($html->find('li.g') as $li)
{
if($k<4)
{
echo $li.'<br>';
$k++;
} else {
?>
<div class="extra_result">
<? echo $li.'<br>';?>
</div>
<?
}
}
然后我只需显示前4个结果,如果用户点击按钮,他会看到extra_result ......
但问题是:当我在浏览器中输入这样的查询时,我得到了有效的结果,但是当我在我的网站上使用它时 - 我得到的结果如下:
2pac shakur
eminem
pets
等等,我从来没有问过他们,我只是无法得到它!
我会感激任何帮助,谢谢你提前!