1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
converter.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\Mail;
4
5
class
Converter
6
{
7
public
static
function
htmlToText
(
string
$body): string
8
{
9
$body = str_replace(
array
(
"\n"
,
"\r"
),
''
, $body);
10
// get <body> inner html if exists
11
$innerBody = trim(preg_replace(
'/(.*?<body[^>]*>)(.*?)(<\/body>.*)/is'
,
'$2'
, $body));
12
$body = $innerBody ?: $body;
13
14
// modify links to text version
15
$body = preg_replace_callback(
16
"%<a[^>]*?href=(['\"])(?<href>[^\1]*?)(?1)[^>]*?>(?<text>.*?)<\/a>%ims"
,
17
function
(
$matches
)
18
{
19
$href =
$matches
[
'href'
];
20
$text
= trim(
$matches
[
'text'
]);
21
if
(!$href)
22
{
23
return
$matches
[0];
24
}
25
$text
= strip_tags(
$text
);
26
return
(
$text
?
"$text:"
:
''
) .
"\n$href\n"
;
27
},
28
$body
29
);
30
31
// change <br> to new line
32
$body = preg_replace(
'/<br(\s*)?\/?>/i'
,
"\n"
, $body);
33
34
$body = preg_replace(
'|(<style[^>]*>)(.*?)(<\/style>)|isU'
,
''
, $body);
35
$body = preg_replace(
'|(<script[^>]*>)(.*?)(<\/script>)|isU'
,
''
, $body);
36
37
// remove tags
38
$body = strip_tags($body);
39
40
// format text to the left side
41
$lines = [];
42
foreach
(explode(
"\n"
, trim($body)) as $line)
43
{
44
$lines[] = trim($line);
45
}
46
47
// remove redundant new lines
48
$body = preg_replace(
"/[\\n]{2,}/"
,
"\n\n"
, implode(
"\n"
, $lines));
49
50
// remove redundant spaces
51
$body = preg_replace(
"/[ \\t]{2,}/"
,
" "
, $body);
52
53
// decode html-entities
54
return
html_entity_decode($body);
55
}
56
}
Bitrix\Main\Mail\Converter
Определения
converter.php:6
Bitrix\Main\Mail\Converter\htmlToText
static htmlToText(string $body)
Определения
converter.php:7
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$text
$text
Определения
template_pdf.php:79
$matches
$matches
Определения
index.php:22
bitrix
modules
main
lib
mail
converter.php
Создано системой
1.14.0