N°6020 New \utils::EscapedHtmlDecode method

This commit is contained in:
Pierre Goiffon
2023-02-23 15:17:46 +01:00
parent bbf6476570
commit 93aee5883b

View File

@@ -1864,20 +1864,37 @@ class utils
return html_entity_decode($sValue, ENT_QUOTES, 'UTF-8');
}
/**
* @param string $sValue value encoded with {@see self::EscapeHtml()}
*
* @return string decoded value
*
* @uses \htmlspecialchars_decode()
* @link https://www.php.net/manual/en/function.htmlspecialchars-decode.php
* @since 3.0.3 3.1.0 N°6020 method creation
*/
public static function EscapedHtmlDecode($sValue)
{
return htmlspecialchars_decode(
$sValue,
ENT_QUOTES | ENT_DISALLOWED | ENT_HTML5
);
}
/**
* Convert a string containing some (valid) HTML markup to plain text
*
* @param string $sHtml
*
* @return string
*/
public static function HtmlToText($sHtml)
{
try
{
try {
//return '<?xml encoding="UTF-8">'.$sHtml;
return \Html2Text\Html2Text::convert('<?xml encoding="UTF-8">'.$sHtml);
}
catch(Exception $e)
{
catch (Exception $e) {
return $e->getMessage();
}
}