Posted By

jamesming on 09/02/08


Tagged

google bot


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

wizard04
sbbath


How to Write Your Own IM Bot in Less Than 5 Minutes


 / Published in: PHP
 

URL: http://www.labnol.org/internet/tutorial-create-bot-for-gtalk-yahoo-messenger/4354/

  1. <?php
  2. // Get all the related keywords from Google Suggest
  3. $u = "http://google.com/complete/search?output=toolbar";
  4. $u = $u . "&q=" . $_REQUEST['msg'];
  5.  
  6. // Using the curl library since dreamhost doesn't allow fopen
  7. $ch = curl_init();
  8. curl_setopt($ch, CURLOPT_URL, $u);
  9. curl_setopt($ch, CURLOPT_HEADER, 0);
  10. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  11.  
  12. $xml = simplexml_load_string(curl_exec($ch));
  13. curl_close($ch);
  14.  
  15. // Parse the keywords and echo them out to the IM window
  16. $result = $xml->xpath('//@data');
  17. while (list($key, $value) = each($result)) {
  18. echo $value ."<br>";
  19. }
  20. ?>

Report this snippet  

You need to login to post a comment.