I have a section of my site that spits out an activity feed using AJAX. A user had gotten this character into one of their strings: Â. For some reason it would cut my JSON string short when using json_encode. I looked at the response PHP gave and it was like nothing existed after the foreign character.
I solved this temporarily by removing foreign characters in the same way I convert strings to URLs safely:
$foreign_char = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u,Ç,Æ,Œ,À,Á,Â,Ã,Ä,Å,È,É,Ê,Ë,Ì,Í,Î,Ï,Ò,Ó,Ô,Õ,Ö,Ù,Ú,Û,Ü");
$english_char = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u,C,AE,OE,A,A,A,A,A,A,E,E,E,E,I,I,I,I,O,O,O,O,O,U,U,U,U");
$desc = str_replace($foreign_char, $english_char, $desc);
$desc = mb_convert_encoding($desc, "ASCII", "UTF-8");
I definitely want users to be able to input foreign characters - has anyone run into anything like this before?