示例#1
0
 /**
  * @param string $charset
  * @return \Curl\CurlResponse
  */
 public function convert($to = "UTF-8", $from = NULL)
 {
     if ($from === NULL) {
         $charset = $this->query['head > meta[http-equiv=Content-Type]']->attr('content');
         $charset = $charset ?: $this->query['head > meta[http-equiv=content-type]']->attr('content');
         $charset = $charset ?: $this->headers['Content-Type'];
         $from = static::getCharset($charset);
     }
     $from = String::upper($from);
     $to = String::upper($to);
     if ($from != $to && $from && $to) {
         if ($body = @iconv($from, $to, $this->body)) {
             $this->Body = ltrim($body);
         } else {
             throw new CurlException("Charset conversion from {$from} to {$to} failed");
         }
     }
     $this->Body = self::fixContentTypeMeta($this->body);
     return $this;
 }