Home » Php » hex – PHP: Convert html-entity-encoded uppercase character to lowercase

hex – PHP: Convert html-entity-encoded uppercase character to lowercase

Posted by: admin July 12, 2020 Leave a comment

Questions:

How can I convert the upper-case html entity characters to their lowercase?

$str = "É"; //É

$res = strtolower( $str );

echo $res;

http://codepad.viper-7.com/Zf3RTe

How to&Answers:
$str = "É"; //É

$res = mb_strtolower(html_entity_decode($str,ENT_COMPAT|ENT_HTML401,'UTF-8'),'UTF-8' );

echo $res;

Answer:

Just use the right function for it:

$strLower = mb_strtolower($str, 'HTML-ENTITIES');

The PHP Multibyte String extensionDocs has an encoding for HTML entities (See list of all supported encodingsDocs).

Answer:

Convert the hexit to decimal and add 32, convert back to hexit.


Or using mbstring:

$res = mb_strtolower(mb_convert_encoding($str, 'UTF-8', 'HTML-ENTITIES'), 'UTF-8')

Answer:

On my server, I don’t have the mbstring extension installed. For a better, cross-server solution you should use this instead:

echo htmlentities(strtoupper(html_entity_decode($str)));