Speed up development with full-stack environments for every branch.

Learn More

How to convert string encoding [mbstring and PHP]

388 Runs 1897 Views 1036 Copies


gtsolutions 373

published 4 years ago


 * PHP mbstring - How to convert string encoding

$str= "A strange string to pass, maybe with some ø, æ, å characters."; 

/* Convert internal character encoding to SJIS */
echo mb_convert_encoding($str, "SJIS")."<br />";

/* Convert EUC-JP to UTF-7 */
echo mb_convert_encoding($str, "UTF-7", "EUC-JP")."<br />";

/* Auto detect encoding from JIS, eucjp-win, sjis-win, then convert str to UCS-2LE */
echo mb_convert_encoding($str, "UCS-2LE", "JIS, eucjp-win, sjis-win")."<br />";

/* "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" */
echo mb_convert_encoding($str, "EUC-JP", "auto")."<br />";

Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).