private static blockquoteToText ( string $text ) : string | ||
$text | string | Text with HTML fragments |
return | string |
private static function blockquoteToText(string $text) : string
{
if (preg_match_all('~(?:<blockquote[^>]*>\\s*)|(?:\\s*</blockquote>)|(?:.+?(?=</?blockquote)|(?:.+))~is', $text, $matches) > 0) {
$text = '';
$offset = 0;
foreach ($matches[0] as $textPart) {
if (($currentOffset = substr_count(strtolower($textPart), '<blockquote')) > 0) {
$offset += $currentOffset;
$textPart = $offset == 1 ? "\n" : '';
// Adds a line to the beginning
} elseif (($currentOffset = substr_count(strtolower($textPart), '</blockquote>')) > 0) {
$offset -= $currentOffset;
$textPart = '';
} elseif ($offset > 0) {
$textPart = "\n" . str_repeat('>', $offset) . ' ' . str_replace("\n", "\n" . str_repeat('>', $offset) . ' ', trim($textPart)) . "\n" . str_repeat('>', $offset);
// Closing tag
}
$text .= $textPart;
}
}
return $text;
}