Advertisement
Guest User

srp

a guest
May 31st, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement