A
A
arinoki2012-01-13 06:19:26
PHP
arinoki, 2012-01-13 06:19:26

php, one more time about encoding

The essence of the subject is as follows.
There is an icecast2 server (this is an audio broadcasting server), it has a page where information about channels is displayed.
By means of php I take away the name of the current track and here the problem waits.
And it lies in the fact that songs with Cyrillic names look something like this - "Alina Grosu - Chalk on asphalt".
I need it to be normal utf-8. I tried the Lebedev decoder - it converts from cp1252 to cp1251.
I tried it myself both through iconv and through mb_character_encoding to convert from cp1252 to utf-8 = even more terrible kryakozyabry is obtained.
______________
So I'm asking the habra community for advice - maybe there is some kind of solution?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Ogra, 2012-01-13
@arinoki

"Alina Grosu - Chalk on asphalt" - what encoding does it come to you?
If it's a single-byte encoding, then you need

$string = iconv('cp1251', 'utf-8', $string);

If it comes to you in utf-8, then you need to do this:
$string = iconv('utf-8', 'cp1252', $string);
$string = iconv('cp1251', 'utf-8', $string);

N
NeOn4eG, 2012-01-13
@NeOn4eG

and yes, you need to convert CP1252 → CP1251 → UTF-8 (or immediately CP1252 → UTF-8), not UTF-8 → CP1252, as you do ...

K
Kirill Gorelov, 2016-03-17
@Kirill-Gorelov

mb_detect_encoding($str); defines the encoding. Just used it myself.
I know it's been 3 years, but I'm sure someone else will come in handy!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question