Created
November 25, 2017 05:58
-
-
Save devtronic/8bc2a015127f0e24e443b059a3494149 to your computer and use it in GitHub Desktop.
This functions check before encoding / decoding if the string is already encoded / decoded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * utf8_encode only once | |
| * | |
| * @param string $data The data | |
| * @return string The converted string | |
| */ | |
| function doUtf8($data) | |
| { | |
| return !preg_match('!!u', $data) ? utf8_encode($data) : $data; | |
| } | |
| /** | |
| * utf8_decode only once | |
| * | |
| * @param string $data The data | |
| * @return string The converted string | |
| */ | |
| function undoUtf8($data) | |
| { | |
| return preg_match('!!u', $data) ? utf8_decode($data) : $data; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment