<?php // Ůńïčøđē
/**
 * @file decoder_charset_inconnu.php.php
 * @brief Page qui tente de décoder un charset inconnu
 *
 * @author hughes monget
 * @see http://monget.com/
 */
header('Content-Type: text/html; charset=UTF-8');
$str_texte_html = $str_texte_base = '';
if (isset($_REQUEST['texte']) && is_string($_REQUEST['texte']) && strlen(trim($_REQUEST['texte'])))
{
    $str_texte_base = $_REQUEST['texte'];
    $str_texte_html = htmlspecialchars($str_texte_base);
    if (isset($_REQUEST['utf8_decode']))
    {
        $str_texte_base = utf8_decode($str_texte_base);
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Décoder un message avec un charset inconnu</title>
        <style type="text/css">
        <!--
        body *
        {
            font-family: monospace;
            font-size: 8pt;
        }
        textarea
        {
            height: 200px;
            width: 600px;
        }
        input.submit
        {
            width: 100px;
        }
        input#wrap        {
            width: 50px;
        }
        -->
        </style>
        <script type="text/javascript">
        <!--;
        //-->
        </script>
    </head>
    <body>
        <form method="post">
            <input type="hidden" name="action" value="action" />
            <textarea id="texte" name="texte"><?php echo $str_texte_html ?></textarea>
            <div>
                <input type="submit" class="submit" value="décoder" />
                <input type="checkbox" id="utf8_decode" name="utf8_decode" <?php if (isset($_REQUEST['utf8_decode'])) { echo 'checked="checked"'; } ?>/><label for="utf8_decode"> utf8_decode ?</label>
            </div>
        </form>
<?php
if ($str_texte_base)
{
    define('WINDOWS_1251', 'Windows-1251');
    $arr_str_encoding = mb_list_encodings();
    if (in_array(WINDOWS_1251, $arr_str_encoding))
    {
        array_unshift($arr_str_encoding, WINDOWS_1251);
        $arr_str_encoding = array_unique($arr_str_encoding);
    }
    $str_texte_base = $_REQUEST['texte'];
    foreach ($arr_str_encoding as $str_encoding)
    {
        $str_texte = utf8_decode($str_texte_base);
        $str_texte = mb_convert_encoding($str_texte, 'UTF-8', $str_encoding);
        $str_encoding = htmlspecialchars($str_encoding, ENT_QUOTES, 'UTF-8');
        $str_texte = htmlspecialchars($str_texte, ENT_QUOTES, 'UTF-8');
        echo '<hr /><pre><b>',$str_encoding,'</b>',"\n",$str_texte,'</pre>';
    }
}
echo '<hr />';
highlight_file(__FILE__);
?>
    </body>
</html>