Foreign Language problems? Not anymore

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Foreign Language problems? Not anymore

Post by D Oliveira » 2020-03-08 22:12

Enjoy folks =)

Image


php

Code: Select all

function detect_encoding($string)
{
    ////w3.org/International/questions/qa-forms-utf-8.html
    if (preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] | [\xC2-\xDF][\x80-\xBF] | \xE0[\xA0-\xBF][\x80-\xBF] | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} | \xED[\x80-\x9F][\x80-\xBF] | \xF0[\x90-\xBF][\x80-\xBF]{2} | [\xF1-\xF3][\x80-\xBF]{3} | \xF4[\x80-\x8F][\x80-\xBF]{2} )*$%xs', $string))
        return 'UTF-8';
 
    //If you need to distinguish between UTF-8 and ISO-8859-1 encoding, list UTF-8 first in your encoding_list.
    //if you list ISO-8859-1 first, mb_detect_encoding() will always return ISO-8859-1.
    return mb_detect_encoding($string, array('UTF-8', 'ASCII', 'ISO-8859-1', 'JIS', 'EUC-JP', 'SJIS'));
}
 
function convert_encoding($string, $to_encoding, $from_encoding = '')
{
    if ($from_encoding == '')
        $from_encoding = detect_encoding($string);
 
    if ($from_encoding == $to_encoding)
        return $string;
 
    return mb_convert_encoding($string, $to_encoding, $from_encoding);
}

php

Code: Select all

$newString = convert_encoding($oldString, 'UTF-8');
html

Code: Select all

<div class="name"><?php echo convert_encoding($recipe['name']);?></div>

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Foreign Language problems? Not anymore

Post by D Oliveira » 2020-03-08 22:18

quick note: DO NOT change charset in your header.php file

Post Reply