$str1 = '日本の山が好きです。나는 한국사람 입니다.';
$str = iconv("UTF-8", "SJIS//TRANSLIT", $str1);
echo $str;
iconv(): Detected an illegal character in input string
$str1 = '日本の山が好きです。나는 한국사람 입니다.';
$str = iconv("UTF-8", "SJIS//TRANSLIT", $str1);
echo $str;
iconv(): Detected an illegal character in input string
I think you have a few misconceptions here:
iconv
doesn't promise to map every character in every writing system to some equivalent in any other writing system.The actual meaning of that option is described in the PHP manual (I've emphasised some key words):
If the string
//TRANSLIT
is appended toto_encoding
, then transliteration is activated. This means that when a character can't be represented in the target charset, it may be approximated through one or several similarly looking characters.
For example, if I run iconv("UTF-8", "ASCII//TRANSLIT", "é")
the result is "e"
, because the version of iconv
I have available has a "transliteration" mapping that says that "e" is "similar looking" to "é".
The error message is simply saying that even with "TRANSLIT" mode turned on, iconv
can't find any way way to represent Hangul characters such as "나" using the Shift-JIS encoding. There is no direct mapping for those characters in the Shift-JIS standard, and it has no rules which define "similar looking" characters to replace them with.