note 109831 added to function.mb-detect-encoding
| From: | ikatalog at web dot de | Date: | Sat, 25 Aug 2012 11:50:57 +0000 |
| Subject: | note 109831 added to function.mb-detect-encoding | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190216@lists.php.net to get a copy of this message | ||
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;
}
// -----------------------------------
?>
----
Server IP: 69.147.83.197
Probable Submitter: 188.193.218.26
----
Manual Page -- http://www.php.net/manual/en/function.mb-detect-encoding.php
Edit -- https://master.php.net/note/edit/109831
Del: integrated -- https://master.php.net/note/delete/109831/integrated
Del: useless -- https://master.php.net/note/delete/109831/useless
Del: bad code -- https://master.php.net/note/delete/109831/bad+code
Del: spam -- https://master.php.net/note/delete/109831/spam
Del: non-english -- https://master.php.net/note/delete/109831/non-english
Del: in docs -- https://master.php.net/note/delete/109831/in+docs
Del: other reasons-- https://master.php.net/note/delete/109831
Reject -- https://master.php.net/note/reject/109831
Search -- https://master.php.net/manage/user-notes.php