note 99311 deleted from function.utf8-encode by cmb
| From: | cmb@php.net | Date: | Sun, 04 Dec 2016 12:13:40 +0000 |
| Subject: | note 99311 deleted from function.utf8-encode by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208201@lists.php.net to get a copy of this message | ||
Note Submitter: darkenergy at hispeed dot ch
----
to encode a string only if it is not yet UTF-8, the most elegant solution i found is:
<?php
//$s is a string from whatever source
mb_detect_encoding($s, "UTF-8") == "UTF-8" ? : $s = utf8_encode($s);
?>
hope it helps