Google texter - v0.2 (PHP)


SUBMITTED BY: scripts4you

DATE: Oct. 21, 2015, 8:58 a.m.

FORMAT: Text only

SIZE: 3.0 kB

HITS: 1526

  1. // start words to search for:
  2. $words = 'php is';
  3. // stop the script after X words
  4. $text_length = 100;
  5. // search for X words on google
  6. $search_length = 3;
  7. // search in the first X google results for new words
  8. $google_pages = 50;
  9. // use this google server
  10. $google_server = 'www.google.com';
  11. // start the search progress
  12. google_texter($words, $text_length, $search_length);
  13. function get_url($url){
  14. // create a new curl resource
  15. $ch = curl_init();
  16. // set URL to download
  17. curl_setopt($ch, CURLOPT_URL, $url);
  18. // user agent:
  19. $browser = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.4)";
  20. curl_setopt($ch, CURLOPT_USERAGENT, $browser);
  21. // remove header? 0 = yes, 1 = no
  22. curl_setopt($ch, CURLOPT_HEADER, 0);
  23. // should curl return or print the data? true = return, false = print
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  25. // timeout in seconds
  26. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  27. // download the given URL, and return output
  28. $output = curl_exec($ch);
  29. // close the curl resource, and free system resources
  30. curl_close($ch);
  31. // print output
  32. return $output;
  33. }
  34. function get_word($words, $search_length){
  35. global $google_pages;
  36. global $google_server;
  37. // split words into an array
  38. $words = explode(" ", $words);
  39. $_words = array_slice($words, ($search_length * -1));
  40. $words = implode(' ', $_words);
  41. $words = strtolower($words);
  42. $url = 'http://'.$google_server.'/';
  43. $url .= 'search?num='.$google_pages.'&';
  44. $url .= 'q=%22'.urlencode($words).'%22&';
  45. $url .= 'btnG=Search';
  46. $content = get_url($url);
  47. $content = strip_tags($content);
  48. $content = strtolower($content);
  49. $content = str_replace("\r\n", " ", $content);
  50. $content = str_replace("\r", " ", $content);
  51. $content = str_replace("\n", " ", $content);
  52. $content = str_replace("\t", " ", $content);
  53. $content = str_replace("<", " ", $content);
  54. $content = str_replace(">", " ", $content);
  55. $content = str_replace('"', " ", $content);
  56. $content = str_replace("'", " ", $content);
  57. $content = str_replace("-", " ", $content);
  58. $content = str_replace(".", " ", $content);
  59. preg_match_all('/'.$words.' ([0-9a-zA-Z������\?!]+)/', $content, $m);
  60. $next_word = isset($m[1]) ? $m[1] : array();
  61. $next_word = array_count_values($next_word);
  62. arsort($next_word);
  63. $next_word = array_keys($next_word);
  64. $r = rand(0,1);
  65. if (isset($next_word[$r])){
  66. return $next_word[$r];
  67. }
  68. if (isset($next_word[0])){
  69. return $next_word[0];
  70. }
  71. return '';
  72. }
  73. function google_texter($start_words, $text_length, $search_length){
  74. $word = $start_words;
  75. print $word;
  76. for ($x=0; $x < $text_length; $x++){
  77. $w = get_word($word, $search_length);
  78. $word .= ' ' . $w;
  79. print ' ' . $w;
  80. }
  81. }

comments powered by Disqus