function get_page ($link, $flag = false) {
        if ($flag === true) @unlink('tmp/cookie.txt');
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $link);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Chrome/16.0.912.75');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'tmp/cookie.txt');
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'tmp/cookie.txt');
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }
 
    function google_page ($page, $link, $key) {
        do {
            $block = explode('id="res"', $page);
            if (empty($block[1])) {
                $urlRecaptchaImage =getImageNameRecaptcha($page);
                $captchaCode = getRecaptcha($urlRecaptchaImage);
                $file = save_google_img($captchaCode);
                do {
                    $responce = recognize($file, $key); // Функция для antigate, нужно передавать путь к сохраненному изображению на сервере и ключ ихний
                    preg_match_all('/error|waiting|not\sready|timelimit/', $responce, $matches);
                } while (!empty($matches[0][0]));
                echo $responce; exit; // Ответ от антигейта
            }
        } while (empty($block[1]));
        $result = $block[1];
        return $result;
    }
 
    function getImageNameRecaptcha($result) {
        preg_match( |src="(http://www.google.com/recaptcha/api/challenge.*?)"|is' , $result, $url_js);
        $result = get_page($url_js[1]);
        preg_match( '|challenge : \'(.*?)\'|is' , $result, $url_pic);
        return $url_pic[1];
    }
 
    function getRecaptcha($url_pic) {
        $picture = get_page("http://api.recaptcha.net/image?c=".$url_pic);
        return $picture;
    }
 
    function save_google_img ($data) {
        $name = 'tmp/'. time() .'.png';
        file_put_contents($name, $data);
        return $name;
    }
 
$link = "http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=$word&num=$count&hl=ua&start=0"; // Ссылка для поиска
$data = get_page($link, true); // Запрос
$result['google_ua'] = google_page($data, $link, $key); // Проверка на капчу, ее решение и получение выдачи гугла