Optimize parse regex

This commit is contained in:
RainLoop Team 2016-06-07 00:59:16 +03:00
parent 08ccf55577
commit c2ab03f69c

View file

@ -189,14 +189,14 @@ class HtmlUtils
$sBodyAttrs = $aMatch[1];
}
$sHtml = \preg_replace('/^.*<body([^>]*)>/sim', '', $sHtml);
$sHtml = \preg_replace('/<\/body>/im', '', $sHtml);
$sHtml = \preg_replace('/<html([^>]*)>/im', '', $sHtml);
$sHtml = \preg_replace('/<\/html>/im', '', $sHtml);
$sHtml = \preg_replace('/^.*<body([^>]*)>/si', '', $sHtml);
$sHtml = \preg_replace('/<\/body>/i', '', $sHtml);
$sHtml = \preg_replace('/<html([^>]*)>/i', '', $sHtml);
$sHtml = \preg_replace('/<\/html>/i', '', $sHtml);
$sHtmlAttrs = \preg_replace('/xmlns:[a-z]="[^"]*"/im', '', $sHtmlAttrs);
$sHtmlAttrs = \preg_replace('/xmlns="[^"]*"/im', '', $sHtmlAttrs);
$sBodyAttrs = \preg_replace('/xmlns:[a-z]="[^"]*"/im', '', $sBodyAttrs);
$sHtmlAttrs = \preg_replace('/xmlns:[a-z]="[^"]*"/i', '', $sHtmlAttrs);
$sHtmlAttrs = \preg_replace('/xmlns="[^"]*"/i', '', $sHtmlAttrs);
$sBodyAttrs = \preg_replace('/xmlns:[a-z]="[^"]*"/i', '', $sBodyAttrs);
return $sHtml;
}
@ -229,8 +229,8 @@ class HtmlUtils
{
return \preg_replace(array(
'/<p[^>]*><\/p>/i',
'/<!doctype[^>]*>/msi',
'/<\?xml [^>]*\?>/msi'
'/<!doctype[^>]*>/i',
'/<\?xml [^>]*\?>/i'
), '', $sHtml);
}
@ -827,8 +827,11 @@ class HtmlUtils
$oDom = \MailSo\Base\HtmlUtils::GetDomFromText($sHtml);
unset($sHtml);
if ($oDom)
if (!$oDom)
{
return '';
}
if ($fAdditionalDomReader)
{
$oResDom = \call_user_func($fAdditionalDomReader, $oDom);
@ -1119,8 +1122,6 @@ class HtmlUtils
}
$sResult = \MailSo\Base\HtmlUtils::GetTextFromDom($oDom, $bWrapByFakeHtmlAndBodyDiv);
}
unset($oDom);
return $sResult;