HosipLan

Untitled

Jan 26th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1.     /**
  2.      * @param \Kdyby\Curl\CurlWrapper $curl
  3.      * @return string
  4.      */
  5.     public static function convertEncoding(CurlWrapper $curl)
  6.     {
  7.         if (Strings::checkEncoding($response = $curl->response)) {
  8.             return Strings::normalize($response);
  9.         }
  10.  
  11.         if ($charset = static::charsetFromContentType($curl->info['content_type'])) {
  12.             $response = @iconv($charset, 'UTF-8', $response);
  13.  
  14.         } else {
  15.             if ($contentType = Strings::match($response, '~<(?P<el>meta[^>]+Content-Type[^>]+)>~i')) {
  16.                 foreach (Nette\Utils\Html::el($contentType['el'])->attrs as $attr => $value) {
  17.                     if (strtolower($attr) !== 'content') {
  18.                         continue;
  19.                     }
  20.  
  21.                     if ($charset = static::charsetFromContentType($value)) {
  22.                         $response = @iconv($charset, 'UTF-8', $response);
  23.                         $response = static::fixContentTypeMeta($response);
  24.                         break;
  25.                     }
  26.                 }
  27.  
  28.             }
  29.         }
  30.  
  31.         return Strings::normalize($response);
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment