note 109831 deleted from function.mb-detect-encoding by aharvey

From: Date: Mon, 05 Nov 2012 03:18:27 +0000
Subject: note 109831 deleted from function.mb-detect-encoding by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191666@lists.php.net to get a copy of this message
Note Submitter: ikatalog at web dot de ---- a) encode to UTF-8 ... only if $string is not encoded yet (prevent double encoding) <?php // ----------------------------------- // -------- encode to UTF-8 ---------- // ----------------------------------- function str_encode_utf8($string) { if (mb_detect_encoding($string, 'UTF-8', true) === FALSE) { $string = utf8_encode($string); } return $string; } // ----------------------------------- ?> b) decode from UTF-8 ... only if $string is ecoded <?php // ----------------------------------- // -------- decode from UTF-8 -------- // ----------------------------------- function str_decode_utf8($string) { if (mb_detect_encoding($string, 'UTF-8', true) === TRUE) { $string = utf8_decode($string); } return $string; } // ----------------------------------- ?>

« previous php.notes (#191666) next »