/**
 * Returns an ISO-8859-1 encoded string if UTF-8 encoded and current charset not UTF-8
 *
 * @param string $str the encode string
 * @param boolean $htmlentities [optional] whether to convert applicable characters to HTML entities
 *
 * @return string
 */
function tbg_decodeUTF8($str, $htmlentities = false)
{
    if (tbg_isUTF8($str) && !mb_stristr(\thebuggenie\core\framework\Context::getI18n()->getCharset(), 'UTF-8')) {
        $str = utf8_decode($str);
    }
    if ($htmlentities) {
        $str = htmlentities($str, ENT_NOQUOTES + ENT_IGNORE, \thebuggenie\core\framework\Context::getI18n()->getCharset());
    }
    return $str;
}
Esempio n. 2
0
/**
 * Returns an ISO-8859-1 encoded string if UTF-8 encoded and current charset not UTF-8
 *
 * @param string $str the encode string
 * @param boolean $htmlentities [optional] whether to convert applicable characters to HTML entities
 * 
 * @return string
 */
function tbg_decodeUTF8($str, $htmlentities = false)
{
    if (tbg_isUTF8($str) && !stristr(TBGContext::getI18n()->getCharset(), 'UTF-8')) {
        $str = utf8_decode($str);
    }
    if ($htmlentities) {
        $str = htmlentities($str, ENT_NOQUOTES + ENT_IGNORE, TBGContext::getI18n()->getCharset());
    }
    return $str;
}