Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

php - UTF8 to latin1_swedish_ci

There are a lot of topics about latin1_swedisch_ci to utf8 conversion. But what about the other way around? I'm dealing for quite a long time with this problem and I haven't found a solution so far. Since I don't know what else is accessing this database, I don't want to change the character encoding of the table.

I have in the table a column which is formatted in latin1_swedisch_ci. Now I have to write queries in php. This database contains German and French names, meaning that I have characters like ?,?,? and so on. How can I do that?

As an example if I want to query the name 'Bürki', then I have to write something like $name='B??rki'. Is there a proper way to convert it to latin1_swedisch_ci without using string replacement for those special characters?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

iconv() will convert strings from one encoding to the other.

The encodings that are of interest to you are utf-8 and iso-8859-1 - the latter is equivalent with latin1.

The "swedish", "german" etc. localizations affect issues like sorting only, the character encoding is always the same.

PS.

then I have to write something like $name='B??rki'.

If you encode your source file as UTF-8, you can write Bürki directly. (You would then have to convert that string into iso-8859-1)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...