Beispiel #1
0
/**
 * Converts html string to given charset
 * @since 1.4.4 and 1.5.1
 * @param string $string
 * @param string $charset
 * @param boolean $htmlencode keep htmlspecialchars encoding
 * @param string
 */
function charset_encode($string, $charset, $htmlencode = true)
{
    global $default_charset;
    $encode = fixcharset($charset);
    $encodefile = SM_PATH . 'functions/encode/' . $encode . '.php';
    if ($encode != 'index' && file_exists($encodefile)) {
        include_once $encodefile;
        $ret = call_user_func('charset_encode_' . $encode, $string);
    } elseif (file_exists(SM_PATH . 'functions/encode/us_ascii.php')) {
        // function replaces all 8bit html entities with question marks.
        // it is used when other encoding functions are unavailable
        include_once SM_PATH . 'functions/encode/us_ascii.php';
        $ret = charset_encode_us_ascii($string);
    } else {
        /**
         * fix for yahoo users that remove all us-ascii related things
         */
        $ret = $string;
    }
    /**
     * Undo html special chars, some places (like compose form) have
     * own sanitizing functions and don't need html symbols.
     * Undo chars only after encoding in order to prevent conversion of 
     * html entities in plain text emails.
     */
    if (!$htmlencode) {
        $ret = str_replace(array('&amp;', '&gt;', '&lt;', '&quot;'), array('&', '>', '<', '"'), $ret);
    }
    return $ret;
}
Beispiel #2
0
/**
 * Converts html string to given charset
 * @since 1.5.1
 * @param string $string
 * @param string $charset
 * @param boolean $htmlencode keep htmlspecialchars encoding
 * @param string
 */
function charset_encode($string, $charset, $htmlencode = true)
{
    global $default_charset;
    // Undo html special chars
    if (!$htmlencode) {
        $string = str_replace(array('&amp;', '&gt;', '&lt;', '&quot;'), array('&', '>', '<', '"'), $string);
    }
    $encode = fixcharset($charset);
    $encodefile = SM_PATH . 'functions/encode/' . $encode . '.php';
    if (file_exists($encodefile)) {
        include_once $encodefile;
        $ret = call_user_func('charset_encode_' . $encode, $string);
    } else {
        include_once SM_PATH . 'functions/encode/us_ascii.php';
        $ret = charset_encode_us_ascii($string);
    }
    return $ret;
}