function AbstractHeader::createPhrase
Produces a compliant, formatted RFC 2822 'phrase' based on the string given.
Parameters
string $string as displayed:
bool $shorten the first line to make remove for header name:
2 calls to AbstractHeader::createPhrase()
- MailboxHeader::getBodyAsString in vendor/
symfony/ mime/ Header/ MailboxHeader.php - Gets the header's body, prepared for folding into a final header value.
- MailboxListHeader::getAddressStrings in vendor/
symfony/ mime/ Header/ MailboxListHeader.php - Gets the full mailbox list of this Header as an array of valid RFC 2822 strings.
File
-
vendor/
symfony/ mime/ Header/ AbstractHeader.php, line 88
Class
- AbstractHeader
- An abstract base MIME Header.
Namespace
Symfony\Component\Mime\HeaderCode
protected function createPhrase(HeaderInterface $header, string $string, string $charset, bool $shorten = false) : string {
// Treat token as exactly what was given
$phraseStr = $string;
// If it's not valid
if (!preg_match('/^' . self::PHRASE_PATTERN . '$/D', $phraseStr)) {
// .. but it is just ascii text, try escaping some characters
// and make it a quoted-string
if (preg_match('/^[\\x00-\\x08\\x0B\\x0C\\x0E-\\x7F]*$/D', $phraseStr)) {
foreach ([
'\\',
'"',
] as $char) {
$phraseStr = str_replace($char, '\\' . $char, $phraseStr);
}
$phraseStr = '"' . $phraseStr . '"';
}
else {
// ... otherwise it needs encoding
// Determine space remaining on line if first line
if ($shorten) {
$usedLength = \strlen($header->getName() . ': ');
}
else {
$usedLength = 0;
}
$phraseStr = $this->encodeWords($header, $string, $usedLength);
}
}
elseif (str_contains($phraseStr, '(')) {
foreach ([
'\\',
'"',
] as $char) {
$phraseStr = str_replace($char, '\\' . $char, $phraseStr);
}
$phraseStr = '"' . $phraseStr . '"';
}
return $phraseStr;
}