note 106858 modified in function.get-html-translation-table by danbrown

From: Date: Tue, 03 Jan 2012 22:15:22 +0000
Subject: note 106858 modified in function.get-html-translation-table by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185341@lists.php.net to get a copy of this message
The fact that MS-word and some other sources use CP-1252, and that it is so close to Latin1 ('ISO-8859-1') causes a lot of confusion. What confused me the most was finding that mySQL uses CP-1252 by default. You may run into trouble if you find yourself tempted to do something like this: <?php $trans[chr(149)] = '&bull;'; // Bullet $trans[chr(150)] = '&ndash;'; // En Dash $trans[chr(151)] = '&mdash;'; // Em Dash $trans[chr(152)] = '&tilde;'; // Small Tilde $trans[chr(153)] = '&trade;'; // Trade Mark Sign ?> Don't do it. DON'T DO IT! You can use: <?php $translationTable = get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'WINDOWS-1252'); ?> or just convert directly: <?php $output = htmlentities($input, ENT_NOQUOTES, 'WINDOWS-1252'); ?> But your web page is probably encoded UTF-8, and you probably don't really want CP-1252 text flying around, so fix the character encoding first: <?php $output = mb_convert_encoding($input, 'UTF-8', 'WINDOWS-1252'); $ouput = htmlentities($output); ?> --was-- The fact that MS-word and some other sources use CP-1252, and that it is so close to Latin1 ('ISO-8859-1') causes a lot of confusion. What confused me the most was finding that mySQL uses CP-1252 by default. You may run into trouble if you find yourself tempted to do something like this: $trans[chr(149)] = '&bull;'; // Bullet $trans[chr(150)] = '&ndash;'; // En Dash $trans[chr(151)] = '&mdash;'; // Em Dash $trans[chr(152)] = '&tilde;'; // Small Tilde $trans[chr(153)] = '&trade;'; // Trade Mark Sign Don't do it. DON'T DO IT! You can use: $translationTable = get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'WINDOWS-1252'); or just convert directly: $output = htmlentities($input, ENT_NOQUOTES, 'WINDOWS-1252'); But your web page is probably encoded UTF-8, and you probably don't really want CP-1252 text flying around, so fix the character encoding first: $output = mb_convert_encoding($input, 'UTF-8', 'WINDOWS-1252'); $ouput = htmlentities($output); http://php.net/manual/en/function.get-html-translation-table.php

« previous php.notes (#185341) next »