note 102382 modified in function.utf8-encode by danbrown

From: Date: Fri, 11 Feb 2011 14:53:29 +0000
Subject: note 102382 modified in function.utf8-encode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176904@lists.php.net to get a copy of this message
I tried a lot of things, but this seems to be the final fail save method to convert any string to proper UTF-8. <?php function _convert($content) { if(!mb_check_encoding($content, 'UTF-8') OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) { $content = mb_convert_encoding($content, 'UTF-8'); if (mb_check_encoding($content, 'UTF-8')) { // log('Converted to UTF-8'); } else { // log('Could not converted to UTF-8'); } } return $content; } ?> --was-- Forgot the return in the previous note: <?php function _convert($content) { if(!mb_check_encoding($content, 'UTF-8') OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) { $content = mb_convert_encoding($content, 'UTF-8'); if (mb_check_encoding($content, 'UTF-8')) { // log('Converted to UTF-8'); } else { // log('Could not converted to UTF-8'); } } return $content; } ?> http://php.net/manual/en/function.utf8-encode.php

« previous php.notes (#176904) next »