iconv() Vs. utf8_encode()
when you have a charset different of UTF-8
Nope - utf8_encode()
is suitable only for converting a ISO-8859-1 string to UTF-8. Iconv provides a vast number of source and target encodings.
Re performance, I have no idea how utf8_encode()
works internally and what libraries it uses, but my prediction is there won't be much of a difference - at least not on "normal" amounts of data in the bytes or kilobytes. If in doubt, do a benchmark.
I tend to use iconv()
because it's clearer that there is a conversion from character set A to character set B.
Also, iconv()
provides more detailed control on what to do when it encounters invalid data. Adding //IGNORE
to the target character set will cause it to silently drop invalid characters. This may be helpful in certain situations.
I recommend you to write your own function.It will be 2-3 lines long and it will be better than struggling with locale, iconv etc. issues.
For example:Fix Turkish Charset Issue Html / PHP (iconv?)