本文整理汇总了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"));
//.........这里部分代码省略.........
示例2: toUTF8
function toUTF8($filesystemElement)
{
$enc = SystemTextEncoding::getEncoding();
return SystemTextEncoding::changeCharset($enc, "UTF-8", $filesystemElement);
}
示例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);
}
示例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);
}