PHP iconv solves utf 8 and gb2312 encoding conversion problems
- 2020-03-31 20:37:53
- OfStack
Finally, I found the answer.
That's how it works on the Internet
This is the right thing to do. It looks like utf-8 is converted to gb2312, but in practice, it always fails. Why?
The reason is actually quite simple, because any function is executed incorrectly, and unfortunately the iconv(); Then something goes wrong. Here's the right answer.
The real answer is this
Very simple, just add a //IGNORE after the line, plus this can be ICONV() function IGNORE the error, continue to execute.
Similarly, to replace gb2312 with utf-8, just say $content = iconv("gb2312","utf-8//IGNORE",$content); just
That's how it works on the Internet
$content = iconv("utf-8","gb2312",$content);
This is the right thing to do. It looks like utf-8 is converted to gb2312, but in practice, it always fails. Why?
The reason is actually quite simple, because any function is executed incorrectly, and unfortunately the iconv(); Then something goes wrong. Here's the right answer.
The real answer is this
$content = iconv("utf-8","gb2312//IGNORE",$content);
Very simple, just add a //IGNORE after the line, plus this can be ICONV() function IGNORE the error, continue to execute.
Similarly, to replace gb2312 with utf-8, just say $content = iconv("gb2312","utf-8//IGNORE",$content); just