mysql - PHP encoding issues


I just uploaded a new site, and am having the strangest issue. I have an ajax/php search box that displays search results as the user is typing. For some reason on the live site the search results aren't always encoded properly. At times it displays correctly, but then 2 seconds later the results will look something like this:

���Ak� ���A<��l��&C-�F�2J�M����v��_ �]v��x���x�Q���(|ȩΜO����-x������q�ʎ�(N��(�����S�8�u���}¸�l���:(�j��N����C����:��u�x�?=���9se-�j�{����� r�՞b1ؑ�Ov�*[nZp"t5�(�h�� Mh���Mg��̆1z�����"�P��G�9e�dD_R�����8n%���.J^������g7��C8�hs��}�qa�$

I uploaded the site to a different web host during development and did not have this issue. I've triedutf8_encode() but it doesn't help. Everything else on the site looks fine, it's only the search results. Any suggestions are greatly appreciated.




You may need to add something like the following between your head tags.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">



I implemented an ajax/php search box a year ago and had big problems when names had accents in them. One part of the solution involved changing the character set on the MySQL table to utf8 (it had been latin1 but I couldn't find a way to get that to work).

Then in the ajax PHP script that returned the search suggestions data, I added this line at the beginning:

header('Content-type: application/json; charset=utf-8');

It's quite likely your new hosting service has different defaults for character types in the MySQL tables and/or the webpages.

People are also looking for solutions to the problem: php - codeigniter join changing id from one table's id to another


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.