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
.
I've tried utf8_encode()
and utf8_decode()
, even with mb_check_encoding()
but it keeps getting through and causing havoc.
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?
Update. Here is a way to reproduce it:
echo json_encode(pack("H*" ,'c32e'));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…