I
I
IDMan2011-01-10 15:25:25
Data conversion
IDMan, 2011-01-10 15:25:25

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

5 answer(s)
H
hayk, 2011-01-10
@IDMan

Try like this:

mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8');

Z
zizop, 2011-01-10
@zizop

This usually works for me:

$converted = mb_convert_encoding($src_string, 'UTF-8', mb_detect_encoding($src_string));

R
Rinoa, 2011-01-10
@Rinoa

Maybe it's worth trying to set the encoding when connecting?
set names latin1

E
Eugene, 2011-01-10
@Nc_Soft

1. try in iconv LATIN1
2. try to convert at db level insert into tbl sel pole=CONVERT(_latin1'Müller' USING utf8)

V
Vitaly Zheltyakov, 2011-01-11
@VitaZheltyakov

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 question

Ask a Question

731 491 924 answers to any question