Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> google - sprawdzacz pozycji
SHiP
post
Post #1





Grupa: Zarejestrowani
Postów: 697
Pomógł: 47
Dołączył: 19.12.2003
Skąd: Lublin

Ostrzeżenie: (0%)
-----


  1. <?php
  2. $keyword = (isset($_GET['keyword'])) ? $_GET['keyword'] : 'php';
  3. $website = (isset($_GET['website'])) ? $_GET['website'] : 'php.pl';
  4.  
  5. $curl = curl_init();
  6. curl_setopt($curl, CURLOPT_HEADER, 0);
  7. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  8. curl_setopt($curl, CURLOPT_VERBOSE, 1);
  9. curl_setopt($curl, CURLOPT_REFERER, 'www.google.pl');
  10. curl_setopt($curl, CURLOPT_URL, 'http://www.google.pl/search?hl=pl&q='.urlencode($keyword).'&num=100');
  11. $google = curl_exec($curl);
  12. curl_close($curl);
  13.  
  14. if(isset($_GET['sub']) && $_GET['sub']=='on') $regEx = '/<div class=g><h2 class=r><a href="(.*?)" class=l>/';
  15. else $regEx = '/<h2 class=r><a href="(.*?)" class=l>/';
  16.  
  17. preg_match_all($regEx, $google, $results);
  18.  
  19. $found = false;
  20. for($i=0; isset($results[1][$i]);$i++) {
  21. $temp = strip_tags($results[1][$i]);
  22. if(strpos($temp, $website)!==false)
  23. {
  24. echo ($i+1).'. '.$temp.'<br/>';
  25. echo('Pozycja '.$website.' : '.($i+1));
  26. $found = true;
  27. break;
  28. }
  29. else echo ($i+1).'. '.$temp.'<br/>';
  30. }
  31. if(!$found) echo 'Nie odnaleziono witryny w pierwszych 100 wynikach google';
  32. ?>
  33.  
  34. <form action="google.php" method="get">
  35. <p>Keyword: <input type="text" name="keyword" value="<?php if(isset($_GET['keyword'])) echo $_GET['keyword']; ?>" /></p>
  36. <p>Website: <input type="text" name="website" value="<?php if(isset($_GET['website'])) echo $_GET['website']; ?>" /></p>
  37. <p>Pomin podstrony <input type="checkbox" <?php if(isset($_GET['sub']) && $_GET['sub']=='on') echo 'checked="checked"'; ?> name="sub"/></p>
  38. <p><input type="submit" value="Oblicz!" /></p>
  39. </form>


W pierwszym inpucie podajemy np: php w drugim php.pl
Otrzymamy wynik - druga pozycja na google


--------------------
Warsztat: Kubuntu, PhpStorm, Opera
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 11:53