Subversion Repositories php_utils

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * Google GetCache
  5.  * Copyright 2015 Daniel Marschall, ViaThinkSoft
  6.  * Version 2015-06-26
  7.  *
  8.  * Licensed under the Apache License, Version 2.0 (the "License");
  9.  * you may not use this file except in compliance with the License.
  10.  * You may obtain a copy of the License at
  11.  *
  12.  *     http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing, software
  15.  * distributed under the License is distributed on an "AS IS" BASIS,
  16.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.  * See the License for the specific language governing permissions and
  18.  * limitations under the License.
  19.  */
  20.  
  21. function google_getcache($url) {
  22.         $options = array(
  23.           'http'=>array(
  24.             'method'=>"GET",
  25.             'header'=>"Accept-language: en\r\n" .
  26.                       "Cookie: foo=bar\r\n" .  // check function.stream-context-create on php.net
  27.                       "User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
  28.           )
  29.         );
  30.  
  31.         $context = stream_context_create($options);
  32.  
  33.         $url = 'https://www.google.de/search?q='.urlencode($url);
  34.         $cont = file_get_contents($url, false, $context);
  35.         preg_match_all('@(http://webcache.googleusercontent.com/.+)"@ismU', $cont, $m);
  36.         if (!isset($m[1][0])) return false;
  37.         $url = urldecode($m[1][0]);
  38.         return file_get_contents($url, false, $context);
  39. }
  40.