本文整理汇总了PHP中Format::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP Format::encode方法的具体用法?PHP Format::encode怎么用?PHP Format::encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Format
的用法示例。
在下文中一共展示了Format::encode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Parse RFC 2397 formatted data strings. Format according to the RFC
* should look something like:
*
* data:[type/subtype][;charset=utf-8][;base64],data[#filename]
*
* Parameters:
* $data - (string) RFC2397 formatted data string
* $output_encoding - (string:optional) Character set the input data
* should be encoded to.
* $always_convert - (bool|default:true) If the input data string does
* not specify an input encding, assume iso-8859-1. If this flag is
* set, the output will always be transcoded to the declared
* output_encoding, if set.
*
* Returs:
* array (data=>parsed and transcoded data string, type=>MIME type
* declared in the data string or text/plain otherwise)
*
* References:
* http://www.ietf.org/rfc/rfc2397.txt
*/
static function parse($data, $output_encoding = false, $always_convert = true)
{
if (substr($data, 0, 5) != "data:") {
return array('data' => $data, 'type' => 'text/plain');
}
$data = substr($data, 5);
list($meta, $contents) = explode(",", $data, 2);
if ($meta) {
list($type, $extra) = explode(";", $meta, 2);
} else {
$extra = '';
}
if (!isset($type) || !$type) {
$type = 'text/plain';
}
$parameters = explode(";", $extra);
# Handle 'charset' hint in $extra, such as
# data:text/plain;charset=iso-8859-1,Blah
# Convert to utf-8 since it's the encoding scheme for the database.
$charset = $always_convert ? 'iso-8859-1' : false;
foreach ($parameters as $p) {
list($param, $value) = explode('=', $extra);
if ($param == 'charset') {
$charset = $value;
} elseif ($param == 'base64') {
$contents = base64_decode($contents);
}
}
if ($output_encoding && $charset) {
$contents = Format::encode($contents, $charset, $output_encoding);
}
return array('data' => $contents, 'type' => $type);
}
示例2: translate
function translate($string)
{
if ($this->short_circuit) {
return $string;
}
// Caching enabled, get translated string from cache
if (isset($this->cache_translations[$string])) {
$string = $this->cache_translations[$string];
}
if (!$this->encode) {
return $string;
}
return Format::encode($string, 'utf-8', $this->charset);
}
示例3: mimedecode
function mimedecode($text, $encoding = 'UTF-8')
{
if (function_exists('imap_mime_header_decode') && ($parts = imap_mime_header_decode($text))) {
$str = '';
foreach ($parts as $part) {
$str .= Format::encode($part->text, $part->charset, $encoding);
}
$text = $str;
} elseif (function_exists('iconv_mime_decode')) {
$text = iconv_mime_decode($text, 0, $encoding);
} elseif (!strcasecmp($encoding, 'utf-8') && function_exists('imap_utf8')) {
$text = imap_utf8($text);
}
return $text;
}
示例4: decode
function decode($what, $errors = false)
{
if (function_exists('imap_mime_header_decode') && ($parts = imap_mime_header_decode($text))) {
$str = '';
foreach ($parts as $part) {
$str .= Format::encode($part->text, $part->charset, $encoding);
}
return $str;
} elseif ($text[0] == '=' && function_exists('iconv_mime_decode')) {
return iconv_mime_decode($text, 0, $encoding);
// TODO: Use a pure-PHP version to perform the decoding
} elseif (!strcasecmp($encoding, 'utf-8') && function_exists('imap_utf8')) {
return imap_utf8($text);
}
return $text;
}
示例5: getBody
function getBody($type = 'text/html', $encoding = false)
{
// First select the body
switch ($type) {
case 'text/html':
$body = $this->BodyHtml;
break;
default:
return false;
}
// Figure out the source encoding (§5.1.2)
$charset = false;
if (@$this->OemCodepage) {
$charset = 'cp' . $this->OemCodepage;
} elseif (@$this->InternetCodepage) {
$charset = 'cp' . $this->InternetCodepage;
}
// Transcode it
if ($encoding && $charset) {
$body = Format::encode($body, $charset, $encoding);
}
return $body;
}
示例6: mime_decode
function mime_decode($text, $encoding = 'utf-8')
{
if (function_exists('mb_detect_encoding')) {
if (($src_enc = mb_detect_encoding($text)) && strcasecmp($src_enc, 'ASCII') !== 0) {
return Format::encode($text, $src_enc, $encoding);
}
}
$str = '';
$parts = imap_mime_header_decode($text);
foreach ($parts as $part) {
$str .= $this->mime_encode($part->text, $part->charset, $encoding);
}
return $str ? $str : imap_utf8($text);
}
示例7: run
//.........这里部分代码省略.........
// then returning the error to the error output stream.
try {
while ($dlen > 0) {
$read_size = min($dlen, $bk->getBlockSize());
$contents = '';
// reading from the stream will likely return an amount of
// data different from the backend requested block size. Loop
// until $read_size bytes are recieved.
while ($read_size > 0 && ($block = fread($stream, $read_size))) {
$contents .= $block;
$read_size -= strlen($block);
}
if ($read_size != 0) {
// short read
throw new Exception(sprintf('%s: Some contents are missing from the stream', $f->getName()));
}
// Calculate MD5 and SHA1 hashes of the file to verify
// contents after successfully written to backend
if (!$bk->write($contents)) {
throw new Exception('Unable to send file contents to backend');
}
hash_update($md5, $contents);
hash_update($sha1, $contents);
$dlen -= strlen($contents);
$written += strlen($contents);
}
// Some backends cannot handle flush() without a
// corresponding write() call.
if ($written && !$bk->flush()) {
throw new Exception('Unable to commit file contents to backend');
}
// Check the signature hash
if ($finfo['signature']) {
$md5 = base64_encode(hash_final($md5, true));
$sha1 = base64_encode(hash_final($sha1, true));
$sig = str_replace(array('=', '+', '/'), array('', '-', '_'), substr($sha1, 0, 16) . substr($md5, 0, 16));
if ($sig != $finfo['signature']) {
throw new Exception(sprintf('%s: Signature verification failed', $f->getName()));
}
}
// Update file to record current backend
$sql = 'UPDATE ' . FILE_TABLE . ' SET bk=' . db_input($bk->getBkChar()) . ' WHERE id=' . db_input($f->getId());
if (!db_query($sql) || db_affected_rows() != 1) {
return false;
}
} catch (Exception $ex) {
if ($bk) {
$bk->unlink();
}
$this->fail($ex->getMessage());
}
// Read file record footer
$footer = fread($stream, 4);
if (strlen($footer) != 4) {
$this->fail('Unable to read file EOF marker');
}
list(, $footer) = unpack('N', $footer);
// Footer should be EOF\x1c as an int
if ($footer != 0x454f461c) {
$this->fail('Incorrect file EOF marker');
}
}
break;
case 'zip':
// Create a temporary ZIP file
$files = FileModel::objects();
示例8: mime_decode
/**
* Mime header value decoder. Usually unicode characters are encoded
* according to RFC-2047. This function will decode RFC-2047 encoded
* header values as well as detect headers which are not encoded.
*
* Caveats:
* If headers contain non-ascii characters the result of this function
* is completely undefined. If osTicket is corrupting your email
* headers, your mail software is not encoding the header text
* correctly.
*
* Returns:
* Header value, transocded to UTF-8
*/
function mime_decode($text, $encoding = 'utf-8')
{
// Handle poorly or completely un-encoded header values (
if (function_exists('mb_detect_encoding')) {
if (($src_enc = mb_detect_encoding($text)) && strcasecmp($src_enc, 'ASCII') !== 0) {
return Format::encode($text, $src_enc, $encoding);
}
}
// Handle ASCII text and RFC-2047 encoding
$str = '';
$parts = imap_mime_header_decode($text);
foreach ($parts as $part) {
$str .= $this->mime_encode($part->text, $part->charset, $encoding);
}
return $str ? $str : imap_utf8($text);
}
示例9: mime_encode
function mime_encode($text, $charset = null, $encoding = 'utf-8')
{
return Format::encode($text, $charset, $encoding);
}