Skip to content

Commit dd6b0ed

Browse files
authored
Fix E_NOTICE in api_htmlentities function about deprecation with mbstring (#7368)
1 parent be3be90 commit dd6b0ed

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

public/main/inc/lib/internationalization.lib.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,18 +1020,19 @@ function api_to_system_encoding($string, $from_encoding = null, $check_utf8_vali
10201020
*
10211021
* @see http://php.net/manual/en/function.htmlentities
10221022
*/
1023-
function api_htmlentities($string, $quote_style = ENT_COMPAT)
1023+
function api_htmlentities($string, $quote_style = ENT_COMPAT): string
10241024
{
1025-
switch ($quote_style) {
1026-
case ENT_COMPAT:
1027-
$string = str_replace(['&', '"', '<', '>'], ['&amp;', '&quot;', '&lt;', '&gt;'], $string);
1028-
break;
1029-
case ENT_QUOTES:
1030-
$string = str_replace(['&', '\'', '"', '<', '>'], ['&amp;', '&#039;', '&quot;', '&lt;', '&gt;'], $string);
1031-
break;
1025+
$flags = ENT_HTML401;
1026+
1027+
if ($quote_style === ENT_QUOTES) {
1028+
$flags |= ENT_QUOTES;
1029+
} else {
1030+
$flags |= ENT_COMPAT;
10321031
}
10331032

1034-
return mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8');
1033+
$flags |= ENT_SUBSTITUTE;
1034+
1035+
return htmlentities($string, $flags, 'UTF-8');
10351036
}
10361037

10371038
/**

0 commit comments

Comments
 (0)