Page MenuHomePhorge

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$stringString to re-encode.
string$to_encodingTarget encoding name, like "UTF-8".
string$from_encodingSource encoding name, like "ISO-8859-1".
Return
stringInput string, with converted character encoding.