when you have encoding other than UTF-8
Nope - utf8_encode() is only suitable for converting an ISO-8859-1 string to UTF-8. Iconv provides a huge number of source and target encodings.
Re, I have no idea how utf8_encode() works internally and in which libraries it uses, but my prediction will not make much difference - at least not for "normal" amounts of data in bytes or kilobytes. If in doubt, do the test.
I prefer to use iconv() because it is clear that there is a conversion from character set A to character set B.
In addition, iconv() provides more granular control over what to do when it encounters invalid data. Adding //IGNORE to the target character set will cause it to silently discard invalid characters. This may be useful in certain situations.
Pekka 웃
source share