The iconv function and the mb_convert_encoding function have different transcoding features,
1. iconv is fast and naturally preferred, but it has a disadvantage. if you encounter a character that cannot be converted, it will be truncated from there. This causes content to be truncated without reason during transcoding.
2. the efficiency of the mb_convert_encoding function is relatively low, but the unconvertible content will not be truncated, which largely retains the content integrity. But I found that, for example, if there is space in the content, there will be converted content? Symbol, still not perfect.
How can we use these two functions to transcode the characters?
My idea is as follows:
The iconv function is preferred, because it is highly efficient and is a built-in function. Discuz's transcoding function also gives priority to this function. However, when transcoding is incomplete, it is necessary to arrange mb_convert_encoding to clean up the mess. The question is, how can we determine whether transcoding is incomplete?
Reply to discussion (solution)
Although the mb_convert_encoding function needs to load the php_mbstring extension
But once loaded, it cannot be said that it is not a built-in function.
For unidentifiable characters, iconv provides two switches for you to choose from, rather than simply truncation.
// Transcoder is replaced by similar characters
// IGNORE discards and continues
Although the mb_convert_encoding function needs to load the php_mbstring extension
But once loaded, it cannot be said that it is not a built-in function.
For unidentifiable characters, iconv provides two switches for you to choose from, rather than simply truncation.
// Transcoder is replaced by similar characters
// IGNORE discards and continues
It seems that I have added the IGNORE function, but some content transcoding is not ideal.
In other words, sometimes the iconv line is used, but the mb_convert_encoding line is not supported, while the mb_convert_encoding line is not supported by the iconv line.
Although the mb_convert_encoding function needs to load the php_mbstring extension
But once loaded, it cannot be said that it is not a built-in function.
For unidentifiable characters, iconv provides two switches for you to choose from, rather than simply truncation.
// Transcoder is replaced by similar characters
// IGNORE discards and continues
After a test, IGNORE may be able to bypass (Previously Unavailable), but some characters are lost when being converted.
For example, When the symbol is converted to gb2312, The iconv is not converted, but the mb_convert_encoding is converted. Therefore, the two have their own advantages and disadvantages. now I just want to use them perfectly.