本文整理汇总了PHP中Mail_mimePart::explodeQuotedString方法的典型用法代码示例。如果您正苦于以下问题:PHP Mail_mimePart::explodeQuotedString方法的具体用法?PHP Mail_mimePart::explodeQuotedString怎么用?PHP Mail_mimePart::explodeQuotedString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mail_mimePart
的用法示例。
在下文中一共展示了Mail_mimePart::explodeQuotedString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: encodeHeader
/**
* Encodes a header as per RFC2047
*
* @param string $name The header name
* @param string $value The header data to encode
* @param string $charset Character set name
* @param string $encoding Encoding name (base64 or quoted-printable)
* @param string $eol End-of-line sequence. Default: "\r\n"
*
* @return string Encoded header data (without a name)
* @since 1.6.1
*/
public static function encodeHeader($name, $value, $charset = 'ISO-8859-1', $encoding = 'quoted-printable', $eol = "\r\n")
{
// Structured headers
$comma_headers = array('from', 'to', 'cc', 'bcc', 'sender', 'reply-to', 'resent-from', 'resent-to', 'resent-cc', 'resent-bcc', 'resent-sender', 'resent-reply-to', 'mail-reply-to', 'mail-followup-to', 'return-receipt-to', 'disposition-notification-to');
$other_headers = array('references', 'in-reply-to', 'message-id', 'resent-message-id');
$name = strtolower($name);
if (in_array($name, $comma_headers)) {
$separator = ',';
} else {
if (in_array($name, $other_headers)) {
$separator = ' ';
}
}
if (!$charset) {
$charset = 'ISO-8859-1';
}
// Structured header (make sure addr-spec inside is not encoded)
if (!empty($separator)) {
// Simple e-mail address regexp
$email_regexp = '([^\\s<]+|("[^\\r\\n"]+"))@\\S+';
$parts = Mail_mimePart::explodeQuotedString("[\t{$separator}]", $value);
$value = '';
foreach ($parts as $part) {
$part = preg_replace('/\\r?\\n[\\s\\t]*/', $eol . ' ', $part);
$part = trim($part);
if (!$part) {
continue;
}
if ($value) {
$value .= $separator == ',' ? $separator . ' ' : ' ';
} else {
$value = $name . ': ';
}
// let's find phrase (name) and/or addr-spec
if (preg_match('/^<' . $email_regexp . '>$/', $part)) {
$value .= $part;
} else {
if (preg_match('/^' . $email_regexp . '$/', $part)) {
// address without brackets and without name
$value .= $part;
} else {
if (preg_match('/<*' . $email_regexp . '>*$/', $part, $matches)) {
// address with name (handle name)
$address = $matches[0];
$word = str_replace($address, '', $part);
$word = trim($word);
// check if phrase requires quoting
if ($word) {
// non-ASCII: require encoding
if (preg_match('#([^\\s\\x21-\\x7E]){1}#', $word)) {
if ($word[0] == '"' && $word[strlen($word) - 1] == '"') {
// de-quote quoted-string, encoding changes
// string to atom
$search = array("\\\"", "\\\\");
$replace = array("\"", "\\");
$word = str_replace($search, $replace, $word);
$word = substr($word, 1, -1);
}
// find length of last line
if (($pos = strrpos($value, $eol)) !== false) {
$last_len = strlen($value) - $pos;
} else {
$last_len = strlen($value);
}
$word = Mail_mimePart::encodeHeaderValue($word, $charset, $encoding, $last_len, $eol);
} else {
if (($word[0] != '"' || $word[strlen($word) - 1] != '"') && preg_match('/[\\(\\)\\<\\>\\\\.\\[\\]@,;:"]/', $word)) {
// ASCII: quote string if needed
$word = '"' . addcslashes($word, '\\"') . '"';
}
}
}
$value .= $word . ' ' . $address;
} else {
// addr-spec not found, don't encode (?)
$value .= $part;
}
}
}
// RFC2822 recommends 78 characters limit, use 76 from RFC2047
$value = wordwrap($value, 76, $eol . ' ');
}
// remove header name prefix (there could be EOL too)
$value = preg_replace('/^' . $name . ':(' . preg_quote($eol, '/') . ')* /', '', $value);
} else {
// Unstructured header
// non-ASCII: require encoding
if (preg_match('#([^\\s\\x21-\\x7E]){1}#', $value)) {
//.........这里部分代码省略.........