Answer the question
In order to leave comments, you need to log in
Convert UTF-8 to Latin-1?
The PHP script accepts some utf8-encoded text from the client. The encoding is set by jquery. On the server side, you need to convert to text with Latin-1 encoding (used in the database, there is no way to change it).
Used the iconv function:
iconv('UTF-8', 'LATIN-1', $text);
Instead of Latin-1, I also tried LATIN1, ISO-8859-1, but still the output is an empty line. Suggested solutions:
- Somehow make JQuery send the text in the required encoding (on the client page, the encoding is ISO-8859-1). But in general, the line is somehow encoded for compatibility (reminiscent of Russian letters in the URL), so this path is fraught with problems (or not?).
- Solve the problem of missing encoding / inability to convert to it from utf8.
- Choose a similar encoding (as a last resort).
Maybe someone solved a similar problem. I would be very grateful, because the Internet is very stingy with tips :).
UPD:
Interesting, but doesn't work for me:
stackoverflow.com/questions/374425/convert-utf8-ch...
Answer the question
In order to leave comments, you need to log in
This usually works for me:
$converted = mb_convert_encoding($src_string, 'UTF-8', mb_detect_encoding($src_string));
Maybe it's worth trying to set the encoding when connecting?
set names latin1
1. try in iconv LATIN1
2. try to convert at db level insert into tbl sel pole=CONVERT(_latin1'Müller' USING utf8)
As far as I understand, you are working with AJAX, and I suspect that you are sending quite complex data structures. If so, then you will not be able to find the correct option - it does not exist. Some browsers behave unacceptably despite all the tricks.
Although you can try. For adequate work:
- configure php to work in latin encoding (or whatever you need),
- process all incoming data with iconv
- just in case, set the encoding for interacting with the database
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question