Mam taki kod:
<?php
class google
{
public $word;
public $results = 1000;
public function get_results_num()
{
{
return false;
}
{
$this->word = substr($this->word, 0
, strpos($this->word, ".")); }
$url = "http://www.google.com/search?num=1&q=".trim(urlencode($this->word)); $curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPGET, true);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$this->curl_result = curl_exec($curl);
curl_close($curl);
if (preg_match('/(of about <b>([0-9,]+)</b>)/', $this->curl_result, $out)) {
$res = $out[2];
}
return false;
}
public function get_results()
{
$url = "http://www.google.com/search?num=100&q=".trim(urlencode($this->word)); $curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPGET, true);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$this->curl_result = curl_exec($curl);
curl_close($curl);
if (preg_match('#<!--m-->(.*?)<h3 class=r><a href="(.*?)" class=1 onmousedown=(.*?)<!--n-->#', $this->curl_result, $out)) {
$res = $out[1];
return preg_split('#<!--m-->(.*?)<h3 class=r><a href="(.*?)" class=1 onmousedown=(.*?)<!--n-->#',$res); }
}
}
$google = new google;
$google->word = $_GET['q'];
echo $google->get_results_num(); ?>
Pierwsza funkcja działa dobrze, ale druga - nie. W ogóle nie wchodzi w if-a. Co zrobić, aby ta druga (get_results()) zwróciła mi taką tablicę dla zapytania "
a":
<?php
0 => 'http://pl.wikipedia.org/wiki/A',
1 => 'http://pl.wikipedia.org/wiki/Witamina_A',
2 => 'http://a.pl/',
3 => 'http://www.wrower.pl/',
4 => 'http://home.agh.edu.pl/polak/slownik/'
)
?>