當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SystemTextEncoding::changeCharset方法代碼示例

本文整理匯總了PHP中SystemTextEncoding::changeCharset方法的典型用法代碼示例。如果您正苦於以下問題:PHP SystemTextEncoding::changeCharset方法的具體用法?PHP SystemTextEncoding::changeCharset怎麽用?PHP SystemTextEncoding::changeCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SystemTextEncoding的用法示例。


在下文中一共展示了SystemTextEncoding::changeCharset方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: switchAction

 public function switchAction($action, $httpVars, $filesVars)
 {
     if (!isset($this->actions[$action])) {
         return false;
     }
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     $streamData = $repository->streamData;
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId();
     $wrapperClassName = $streamData["classname"];
     if (empty($httpVars["file"])) {
         return;
     }
     $file = $destStreamURL . AJXP_Utils::decodeSecureMagic($httpVars["file"]);
     $mess = ConfService::getMessages();
     $node = new AJXP_Node($file);
     AJXP_Controller::applyHook("node.read", array($node));
     switch ($action) {
         case "eml_get_xml_structure":
             $params = array('include_bodies' => false, 'decode_bodies' => false, 'decode_headers' => 'UTF-8');
             $decoder = $this->getStructureDecoder($file, $wrapperClassName == "imapAccessWrapper");
             $xml = $decoder->getXML($decoder->decode($params));
             if (function_exists("imap_mime_header_decode")) {
                 $doc = new DOMDocument();
                 $doc->loadXML($xml);
                 $xPath = new DOMXPath($doc);
                 $headers = $xPath->query("//headername");
                 $changes = false;
                 foreach ($headers as $headerNode) {
                     if ($headerNode->firstChild->nodeValue == "Subject") {
                         $headerValueNode = $headerNode->nextSibling->nextSibling;
                         $value = $headerValueNode->nodeValue;
                         $elements = imap_mime_header_decode($value);
                         $decoded = "";
                         foreach ($elements as $element) {
                             $decoded .= $element->text;
                             $charset = $element->charset;
                         }
                         if ($decoded != $value) {
                             $value = SystemTextEncoding::changeCharset($charset, "UTF-8", $decoded);
                             $node = $doc->createElement("headervalue", $value);
                             $res = $headerNode->parentNode->replaceChild($node, $headerValueNode);
                             $changes = true;
                         }
                     }
                 }
                 if ($changes) {
                     $xml = $doc->saveXML();
                 }
             }
             print $xml;
             break;
         case "eml_get_bodies":
             require_once "Mail/mimeDecode.php";
             $params = array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => false);
             if ($wrapperClassName == "imapAccessWrapper") {
                 $cache = AJXP_Cache::getItem("eml_remote", $file, null, array("EmlParser", "computeCacheId"));
                 $content = $cache->getData();
             } else {
                 $content = file_get_contents($file);
             }
             $decoder = new Mail_mimeDecode($content);
             $structure = $decoder->decode($params);
             $html = $this->_findPartByCType($structure, "text", "html");
             $text = $this->_findPartByCType($structure, "text", "plain");
             if ($html != false && isset($html->ctype_parameters) && isset($html->ctype_parameters["charset"])) {
                 $charset = $html->ctype_parameters["charset"];
             }
             if (isset($charset)) {
                 header('Content-Type: text/xml; charset=' . $charset);
                 header('Cache-Control: no-cache');
                 print '<?xml version="1.0" encoding="' . $charset . '"?>';
                 print '<email_body>';
             } else {
                 AJXP_XMLWriter::header("email_body");
             }
             if ($html !== false) {
                 print '<mimepart type="html"><![CDATA[';
                 $text = $html->body;
                 print $text;
                 print "]]></mimepart>";
             }
             if ($text !== false) {
                 print '<mimepart type="plain"><![CDATA[';
                 print $text->body;
                 print "]]></mimepart>";
             }
             AJXP_XMLWriter::close("email_body");
             break;
         case "eml_dl_attachment":
             $attachId = $httpVars["attachment_id"];
             if (!isset($attachId)) {
                 break;
             }
             require_once "Mail/mimeDecode.php";
             $params = array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => false);
             if ($wrapperClassName == "imapAccessWrapper") {
                 $cache = AJXP_Cache::getItem("eml_remote", $file, null, array("EmlParser", "computeCacheId"));
//.........這裏部分代碼省略.........
開發者ID:biggtfish,項目名稱:cms,代碼行數:101,代碼來源:class.EmlParser.php

示例2: toUTF8

 function toUTF8($filesystemElement)
 {
     $enc = SystemTextEncoding::getEncoding();
     return SystemTextEncoding::changeCharset($enc, "UTF-8", $filesystemElement);
 }
開發者ID:umbecr,項目名稱:camilaframework,代碼行數:5,代碼來源:class.SystemTextEncoding.php

示例3: toStorageEncoding

 /**
  * Decode a string from UTF8 to current Storage Charset
  * @static
  * @param string $filesystemElement
  * @param bool $test Try to detect if it's really utf8 or not
  * @return string
  */
 public static function toStorageEncoding($filesystemElement, $test = false)
 {
     if ($test && !SystemTextEncoding::isUtf8($filesystemElement)) {
         return $filesystemElement;
     }
     $enc = SystemTextEncoding::getEncoding();
     return SystemTextEncoding::changeCharset("UTF-8", $enc, $filesystemElement);
 }
開發者ID:rcmarotz,項目名稱:pydio-core,代碼行數:15,代碼來源:class.SystemTextEncoding.php

示例4: toUTF8

 /**
  * Transform a string from current charset to utf8
  * @static
  * @param string $filesystemElement
  * @param bool $test Test if it's already UTF8 or not, to avoid double-encoding
  * @return string
  */
 static function toUTF8($filesystemElement, $test = true)
 {
     if ($test && SystemTextEncoding::isUtf8($filesystemElement)) {
         return $filesystemElement;
     }
     $enc = SystemTextEncoding::getEncoding();
     return SystemTextEncoding::changeCharset($enc, "UTF-8", $filesystemElement);
 }
開發者ID:crodriguezn,項目名稱:administrator-files,代碼行數:15,代碼來源:class.SystemTextEncoding.php


注:本文中的SystemTextEncoding::changeCharset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。