- Модуль: sender
- Путь к файлу: ~/bitrix/modules/sender/lib/search/content.php
- Класс: Bitrix\Sender\Search\Content
- Вызов: Content::convertBodyHtmlToText
static function convertBodyHtmlToText($body) { // remove tags $innerBody = preg_replace('/<(script|iframe|style)(.*?)>(.*?)(<\\/\\1.*?>)/is', '', $body); $body = $innerBody ?: $body; // get inner html if exists $innerBody = trim(preg_replace('/(.*?]*>)(.*?)(<\/body>.*)/is', '$2', $body)); $body = $innerBody ?: $body; // modify links to text version $body = preg_replace_callback( "/]*?>([^>]*?)<\\/a>/i", function ($matches) { return $matches[1]; }, $body ); // change
to new line $body = preg_replace('/\
/i', "\n", $body); // remove tags $body = strip_tags($body); // format text to the left side $lines = []; foreach (explode("\n", trim($body)) as $line) { $lines[] = trim($line); } // remove redundant new lines $body = preg_replace("/[\\n]{2,}/", " ", implode(" ", $lines)); // remove redundant spaces $body = preg_replace("/[ \\t]{2,}/", " ", $body); // decode html-entities return html_entity_decode($body); }