Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert any possible format to UTF-8 using Iconv?

Tags:

php

utf-8

iconv

so for example this will turn 1251 into utf-8.

$utf8 = iconv('windows-1251', 'utf-8', $ansi);

But how to turn unknown (when it comes to us we do not know yet what format it is) ( in general any ) format (possibly known by Iconv ) to utf-8? (code sample)

like image 754
Rella Avatar asked May 10 '10 21:05

Rella


1 Answers

You cannot translate from an unknown character set, the best you can do is make a guess about the actual charset and use that guess as first parameter - you can use mb_detect_encoding() for that purpose.

like image 133
soulmerge Avatar answered Nov 15 '22 07:11

soulmerge