Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

srp

By: a guest on May 31st, 2012  |  syntax: PHP  |  size: 0.88 KB  |  views: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function srp_wp_http_xml($url){
  2.     $ch = curl_init();
  3.  
  4.     curl_setopt($ch, CURLOPT_URL, $url);
  5.     curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  6.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  7.     curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
  8.  
  9.     $result = curl_exec($ch);
  10.     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  11.  
  12.     curl_close($ch);
  13.  
  14.     if(!$code){
  15.         preg_match('@^(?:http://)?([^/]+)@i', $url, $matches);
  16.         $host = $matches[1];
  17.         preg_match('/[^.]+\.[^.]+$/', $host, $matches);
  18.         srp_debug(__('Something went wrong. No data is being returned from ' . $matches[0] . '.'), $result);
  19.         return;
  20.     }elseif($code != 200){
  21.         $message = 'Request to URL: "' . $url . '" failed. Response code: ' . $code;
  22.         srp_debug(__($message), $result);
  23.         return;
  24.     }
  25.     $xml = @simplexml_load_string($result);
  26.  
  27.     return $xml;
  28. }