function phutil_utf8_convert($string, $to_encoding, $from_encoding)libphutil Technical Documentation (Core Utilities)
function phutil_utf8_convert($string, $to_encoding, $from_encoding)
libphutil Technical Documentation (Core Utilities)
Convert a string from one encoding (like ISO-8859-1) to another encoding (like UTF-8).
This is primarily a thin wrapper around mb_convert_encoding() which checks you have the extension installed, since we try to require the extension only if you actually need it (i.e., you want to work with encodings other than UTF-8).
NOTE: This function assumes that the input is in the given source encoding.
If it is not, it may not output in the specified target encoding. If you
need to perform a hard conversion to UTF-8, use this function in conjunction
with phutil_utf8ize(). We can detect failures caused by invalid
encoding names, but mb_convert_encoding() fails silently if the
encoding name identifies a real encoding but the string is not actually
encoded with that encoding.
Parameters
string | $string | String to re-encode. |
string | $to_encoding | Target encoding name, like "UTF-8". |
string | $from_encoding | Source encoding name, like "ISO-8859-1". |
Return
string | Input string, with converted character encoding. |
- Defined
- src/utils/utf8.php:683