I'm calling json_encode()
on data that comes from a MySQL database with utf8_general_ci
collation. The problem is that some rows have weird data which I can't clean. For example symbol �
, so once it reaches json_encode()
, it fails with json_encode(): Invalid UTF-8 sequence in argument
.
我试过utf8_encode()
和utf8_decode()
,即使是mb_check_encoding()
也是如此,但它一直在打通,造成了很大的 destruct .
Running PHP 5.3.10 on Mac. So the question is - how can I clean up invalid utf8 symbols, keeping the rest of data, so that json_encoding()
would work?
使现代化下面是一种复制它的方法:
echo json_encode(pack("H*" ,'c32e'));