utf8_encode didn't work for me either. Probably because it converts from ISO-8859-1 to unicode. I wanted to convert from cp1250.
Therefore i created this. If you want to convert from another encoding, just grab at www.unicode.org appropriate table for conversion from your encoding to unicode and apply.
/*
#
Name: cp1250_WinLatin2 to Unicode table
Unicode version: 1.1
Table version: 2.00
Table format: Format A
Date: 03/31/95
General notes: none
#
Format: Three tab-separated columns
Column #1 is the cp1250_WinLatin2 code (in hex)
Column #2 is the Unicode (in hex as 0xXXXX)
Column #3 is the Unicode name (follows a comment sign, '#')
#
The entries are in cp1250_WinLatin2 order
#
*/
$win2utf[0x00]=0x0000; // NULL
$win2utf[0x01]=0x0001; // START OF HEADING
$win2utf[0x02]=0x0002; // START OF TEXT
$win2utf[0x03]=0x0003; // END OF TEXT
$win2utf[0x04]=0x0004; // END OF TRANSMISSION
$win2utf[0x05]=0x0005; // ENQUIRY
$win2utf[0x06]=0x0006; // ACKNOWLEDGE
$win2utf[0x07]=0x0007; // BELL
$win2utf[0x08]=0x0008; // BACKSPACE
$win2utf[0x09]=0x0009; // HORIZONTAL TABULATION
$win2utf[0x0a]=0x000a; // LINE FEED
$win2utf[0x0b]=0x000b; // VERTICAL TABULATION
$win2utf[0x0c]=0x000c; // FORM FEED
$win2utf[0x0d]=0x000d; // CARRIAGE RETURN
$win2utf[0x0e]=0x000e; // SHIFT OUT
$win2utf[0x0f]=0x000f; // SHIFT IN
$win2utf[0x10]=0x0010; // DATA LINK ESCAPE
$win2utf[0x11]=0x0011; // DEVICE CONTROL ONE
$win2utf[0x12]=0x0012; // DEVICE CONTROL TWO
$win2utf[0x13]=0x0013; // DEVICE CONTROL THREE
$win2utf[0x14]=0x0014; // DEVICE CONTROL FOUR
$win2utf[0x15]=0x0015; // NEGATIVE ACKNOWLEDGE
$win2utf[0x16]=0x0016; // SYNCHRONOUS IDLE
$win2utf[0x17]=0x0017; // END OF TRANSMISSION BLOCK
$win2utf[0x18]=0x0018; // CANCEL
$win2utf[0x19]=0x0019; // END OF MEDIUM
$win2utf[0x1a]=0x001a; // SUBSTITUTE
$win2utf[0x1b]=0x001b; // ESCAPE
$win2utf[0x1c]=0x001c; // FILE SEPARATOR
$win2utf[0x1d]=0x001d; // GROUP SEPARATOR
$win2utf[0x1e]=0x001e; // RECORD SEPARATOR
$win2utf[0x1f]=0x001f; // UNIT SEPARATOR
$win2utf[0x20]=0x0020; // SPACE
$win2utf[0x21]=0x0021; // EXCLAMATION MARK
$win2utf[0x22]=0x0022; // QUOTATION MARK
$win2utf[0x23]=0x0023; // NUMBER SIGN
$win2utf[0x24]=0x0024; // DOLLAR SIGN
$win2utf[0x25]=0x0025; // PERCENT SIGN
$win2utf[0x26]=0x0026; // AMPERSAND
$win2utf[0x27]=0x0027; // APOSTROPHE
$win2utf[0x28]=0x0028; // LEFT PARENTHESIS
$win2utf[0x29]=0x0029; // RIGHT PARENTHESIS
$win2utf[0x2a]=0x002a; // ASTERISK
$win2utf[0x2b]=0x002b; // PLUS SIGN
$win2utf[0x2c]=0x002c; // COMMA
$win2utf[0x2d]=0x002d; // HYPHEN-MINUS
$win2utf[0x2e]=0x002e; // FULL STOP
$win2utf[0x2f]=0x002f; // SOLIDUS
$win2utf[0x30]=0x0030; // DIGIT ZERO
$win2utf[0x31]=0x0031; // DIGIT ONE
$win2utf[0x32]=0x0032; // DIGIT TWO
$win2utf[0x33]=0x0033; // DIGIT THREE
$win2utf[0x34]=0x0034; // DIGIT FOUR
$win2utf[0x35]=0x0035; // DIGIT FIVE
$win2utf[0x36]=0x0036; // DIGIT SIX
$win2utf[0x37]=0x0037; // DIGIT SEVEN
$win2utf[0x38]=0x0038; // DIGIT EIGHT
$win2utf[0x39]=0x0039; // DIGIT NINE
$win2utf[0x3a]=0x003a; // COLON
$win2utf[0x3b]=0x003b; // SEMICOLON
$win2utf[0x3c]=0x003c; // LESS-THAN SIGN
$win2utf[0x3d]=0x003d; // EQUALS SIGN
$win2utf[0x3e]=0x003e; // GREATER-THAN SIGN
$win2utf[0x3f]=0x003f; // QUESTION MARK
$win2utf[0x40]=0x0040; // COMMERCIAL AT
$win2utf[0x41]=0x0041; // LATIN CAPITAL LETTER A
$win2utf[0x42]=0x0042; // LATIN CAPITAL LETTER B
$win2utf[0x43]=0x0043; // LATIN CAPITAL LETTER C
$win2utf[0x44]=0x0044; // LATIN CAPITAL LETTER D
$win2utf[0x45]=0x0045; // LATIN CAPITAL LETTER E
$win2utf[0x46]=0x0046; // LATIN CAPITAL LETTER F
$win2utf[0x47]=0x0047; // LATIN CAPITAL LETTER G
$win2utf[0x48]=0x0048; // LATIN CAPITAL LETTER H
$win2utf[0x49]=0x0049; // LATIN CAPITAL LETTER I
$win2utf[0x4a]=0x004a; // LATIN CAPITAL LETTER J
$win2utf[0x4b]=0x004b; // LATIN CAPITAL LETTER K
$win2utf[0x4c]=0x004c; // LATIN CAPITAL LETTER L
$win2utf[0x4d]=0x004d; // LATIN CAPITAL LETTER M
$win2utf[0x4e]=0x004e; // LATIN CAPITAL LETTER N
$win2utf[0x4f]=0x004f; // LATIN CAPITAL LETTER O
$win2utf[0x50]=0x0050; // LATIN CAPITAL LETTER P
$win2utf[0x51]=0x0051; // LATIN CAPITAL LETTER Q
$win2utf[0x52]=0x0052; // LATIN CAPITAL LETTER R
$win2utf[0x53]=0x0053; // LATIN CAPITAL LETTER S
$win2utf[0x54]=0x0054; // LATIN CAPITAL LETTER T
$win2utf[0x55]=0x0055; // LATIN CAPITAL LETTER U
$win2utf[0x56]=0x0056; // LATIN CAPITAL LETTER V
$win2utf[0x57]=0x0057; // LATIN CAPITAL LETTER W
$win2utf[0x58]=0x0058; // LATIN CAPITAL LETTER X
$win2utf[0x59]=0x0059; // LATIN CAPITAL LETTER Y
$win2utf[0x5a]=0x005a; // LATIN CAPITAL LETTER Z
$win2utf[0x5b]=0x005b; // LEFT SQUARE BRACKET
$win2utf[0x5c]=0x005c; // REVERSE SOLIDUS
$win2utf[0x5d]=0x005d; // RIGHT SQUARE BRACKET
$win2utf[0x5e]=0x005e; // CIRCUMFLEX ACCENT
$win2utf[0x5f]=0x005f; // LOW LINE
$win2utf[0x60]=0x0060; // GRAVE ACCENT
$win2utf[0x61]=0x0061; // LATIN SMALL LETTER A
$win2utf[0x62]=0x0062; // LATIN SMALL LETTER B
$win2utf[0x63]=0x0063; // LATIN SMALL LETTER C
$win2utf[0x64]=0x0064; // LATIN SMALL LETTER D
$win2utf[0x65]=0x0065; // LATIN SMALL LETTER E
$win2utf[0x66]=0x0066; // LATIN SMALL LETTER F
$win2utf[0x67]=0x0067; // LATIN SMALL LETTER G
$win2utf[0x68]=0x0068; // LATIN SMALL LETTER H
$win2utf[0x69]=0x0069; // LATIN SMALL LETTER I
$win2utf[0x6a]=0x006a; // LATIN SMALL LETTER J
$win2utf[0x6b]=0x006b; // LATIN SMALL LETTER K
$win2utf[0x6c]=0x006c; // LATIN SMALL LETTER L
$win2utf[0x6d]=0x006d; // LATIN SMALL LETTER M
$win2utf[0x6e]=0x006e; // LATIN SMALL LETTER N
$win2utf[0x6f]=0x006f; // LATIN SMALL LETTER O
$win2utf[0x70]=0x0070; // LATIN SMALL LETTER P
$win2utf[0x71]=0x0071; // LATIN SMALL LETTER Q
$win2utf[0x72]=0x0072; // LATIN SMALL LETTER R
$win2utf[0x73]=0x0073; // LATIN SMALL LETTER S
$win2utf[0x74]=0x0074; // LATIN SMALL LETTER T
$win2utf[0x75]=0x0075; // LATIN SMALL LETTER U
$win2utf[0x76]=0x0076; // LATIN SMALL LETTER V
$win2utf[0x77]=0x0077; // LATIN SMALL LETTER W
$win2utf[0x78]=0x0078; // LATIN SMALL LETTER X
$win2utf[0x79]=0x0079; // LATIN SMALL LETTER Y
$win2utf[0x7a]=0x007a; // LATIN SMALL LETTER Z
$win2utf[0x7b]=0x007b; // LEFT CURLY BRACKET
$win2utf[0x7c]=0x007c; // VERTICAL LINE
$win2utf[0x7d]=0x007d; // RIGHT CURLY BRACKET
$win2utf[0x7e]=0x007e; // TILDE
$win2utf[0x7f]=0x007f; // DELETE
$win2utf[0x80]=0x0080; // NOT USED
$win2utf[0x81]=0x0081; // NOT USED
$win2utf[0x82]=0x201a; // SINGLE LOW-9 QUOTATION MARK
$win2utf[0x83]=0x0083; // NOT USED
$win2utf[0x84]=0x201e; // DOUBLE LOW-9 QUOTATION MARK
$win2utf[0x85]=0x2026; // HORIZONTAL ELLIPSIS
$win2utf[0x86]=0x2020; // DAGGER
$win2utf[0x87]=0x2021; // DOUBLE DAGGER
$win2utf[0x88]=0x0088; // NOT USED
$win2utf[0x89]=0x2030; // PER MILLE SIGN
$win2utf[0x8a]=0x0160; // LATIN CAPITAL LETTER S WITH CARON
$win2utf[0x8b]=0x2039; // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
$win2utf[0x8c]=0x015a; // LATIN CAPITAL LETTER S WITH ACUTE
$win2utf[0x8d]=0x0164; // LATIN CAPITAL LETTER T WITH CARON
$win2utf[0x8e]=0x017d; // LATIN CAPITAL LETTER Z WITH CARON
$win2utf[0x8f]=0x0179; // LATIN CAPITAL LETTER Z WITH ACUTE
$win2utf[0x90]=0x0090; // NOT USED
$win2utf[0x91]=0x2018; // LEFT SINGLE QUOTATION MARK
$win2utf[0x92]=0x2019; // RIGHT SINGLE QUOTATION MARK
$win2utf[0x93]=0x201c; // LEFT DOUBLE QUOTATION MARK
$win2utf[0x94]=0x201d; // RIGHT DOUBLE QUOTATION MARK
$win2utf[0x95]=0x2022; // BULLET
$win2utf[0x96]=0x2013; // EN DASH
$win2utf[0x97]=0x2014; // EM DASH
$win2utf[0x98]=0x0098; // NOT USED
$win2utf[0x99]=0x2122; // TRADE MARK SIGN
$win2utf[0x9a]=0x0161; // LATIN SMALL LETTER S WITH CARON
$win2utf[0x9b]=0x203a; // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
$win2utf[0x9c]=0x015b; // LATIN SMALL LETTER S WITH ACUTE
$win2utf[0x9d]=0x0165; // LATIN SMALL LETTER T WITH CARON
$win2utf[0x9e]=0x017e; // LATIN SMALL LETTER Z WITH CARON
$win2utf[0x9f]=0x017a; // LATIN SMALL LETTER Z WITH ACUTE
$win2utf[0xa0]=0x00a0; // NO-BREAK SPACE
$win2utf[0xa1]=0x02c7; // CARON
$win2utf[0xa2]=0x02d8; // BREVE
$win2utf[0xa3]=0x0141; // LATIN CAPITAL LETTER L WITH STROKE
$win2utf[0xa4]=0x00a4; // CURRENCY SIGN
$win2utf[0xa5]=0x0104; // LATIN CAPITAL LETTER A WITH OGONEK
$win2utf[0xa6]=0x00a6; // BROKEN BAR
$win2utf[0xa7]=0x00a7; // SECTION SIGN
$win2utf[0xa8]=0x00a8; // DIAERESIS
$win2utf[0xa9]=0x00a9; // COPYRIGHT SIGN
$win2utf[0xaa]=0x015e; // LATIN CAPITAL LETTER S WITH CEDILLA
$win2utf[0xab]=0x00ab; // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
$win2utf[0xac]=0x00ac; // NOT SIGN
$win2utf[0xad]=0x00ad; // SOFT HYPHEN
$win2utf[0xae]=0x00ae; // REGISTERED SIGN
$win2utf[0xaf]=0x017b; // LATIN CAPITAL LETTER Z WITH DOT ABOVE
$win2utf[0xb0]=0x00b0; // DEGREE SIGN
$win2utf[0xb1]=0x00b1; // PLUS-MINUS SIGN
$win2utf[0xb2]=0x02db; // OGONEK
$win2utf[0xb3]=0x0142; // LATIN SMALL LETTER L WITH STROKE
$win2utf[0xb4]=0x00b4; // ACUTE ACCENT
$win2utf[0xb5]=0x00b5; // MICRO SIGN
$win2utf[0xb6]=0x00b6; // PILCROW SIGN
$win2utf[0xb7]=0x00b7; // MIDDLE DOT
$win2utf[0xb8]=0x00b8; // CEDILLA
$win2utf[0xb9]=0x0105; // LATIN SMALL LETTER A WITH OGONEK
$win2utf[0xba]=0x015f; // LATIN SMALL LETTER S WITH CEDILLA
$win2utf[0xbb]=0x00bb; // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
$win2utf[0xbc]=0x013d; // LATIN CAPITAL LETTER L WITH CARON
$win2utf[0xbd]=0x02dd; // DOUBLE ACUTE ACCENT
$win2utf[0xbe]=0x013e; // LATIN SMALL LETTER L WITH CARON
$win2utf[0xbf]=0x017c; // LATIN SMALL LETTER Z WITH DOT ABOVE
$win2utf[0xc0]=0x0154; // LATIN CAPITAL LETTER R WITH ACUTE
$win2utf[0xc1]=0x00c1; // LATIN CAPITAL LETTER A WITH ACUTE
$win2utf[0xc2]=0x00c2; // LATIN CAPITAL LETTER A WITH CIRCUMFLEX
$win2utf[0xc3]=0x0102; // LATIN CAPITAL LETTER A WITH BREVE
$win2utf[0xc4]=0x00c4; // LATIN CAPITAL LETTER A WITH DIAERESIS
$win2utf[0xc5]=0x0139; // LATIN CAPITAL LETTER L WITH ACUTE
$win2utf[0xc6]=0x0106; // LATIN CAPITAL LETTER C WITH ACUTE
$win2utf[0xc7]=0x00c7; // LATIN CAPITAL LETTER C WITH CEDILLA
$win2utf[0xc8]=0x010c; // LATIN CAPITAL LETTER C WITH CARON
$win2utf[0xc9]=0x00c9; // LATIN CAPITAL LETTER E WITH ACUTE
$win2utf[0xca]=0x0118; // LATIN CAPITAL LETTER E WITH OGONEK
$win2utf[0xcb]=0x00cb; // LATIN CAPITAL LETTER E WITH DIAERESIS
$win2utf[0xcc]=0x011a; // LATIN CAPITAL LETTER E WITH CARON
$win2utf[0xcd]=0x00cd; // LATIN CAPITAL LETTER I WITH ACUTE
$win2utf[0xce]=0x00ce; // LATIN CAPITAL LETTER I WITH CIRCUMFLEX
$win2utf[0xcf]=0x010e; // LATIN CAPITAL LETTER D WITH CARON
$win2utf[0xd0]=0x0110; // LATIN CAPITAL LETTER D WITH STROKE
$win2utf[0xd1]=0x0143; // LATIN CAPITAL LETTER N WITH ACUTE
$win2utf[0xd2]=0x0147; // LATIN CAPITAL LETTER N WITH CARON
$win2utf[0xd3]=0x00d3; // LATIN CAPITAL LETTER O WITH ACUTE
$win2utf[0xd4]=0x00d4; // LATIN CAPITAL LETTER O WITH CIRCUMFLEX
$win2utf[0xd5]=0x0150; // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
$win2utf[0xd6]=0x00d6; // LATIN CAPITAL LETTER O WITH DIAERESIS
$win2utf[0xd7]=0x00d7; // MULTIPLICATION SIGN
$win2utf[0xd8]=0x0158; // LATIN CAPITAL LETTER R WITH CARON
$win2utf[0xd9]=0x016e; // LATIN CAPITAL LETTER U WITH RING ABOVE
$win2utf[0xda]=0x00da; // LATIN CAPITAL LETTER U WITH ACUTE
$win2utf[0xdb]=0x0170; // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
$win2utf[0xdc]=0x00dc; // LATIN CAPITAL LETTER U WITH DIAERESIS
$win2utf[0xdd]=0x00dd; // LATIN CAPITAL LETTER Y WITH ACUTE
$win2utf[0xde]=0x0162; // LATIN CAPITAL LETTER T WITH CEDILLA
$win2utf[0xdf]=0x00df; // LATIN SMALL LETTER SHARP S
$win2utf[0xe0]=0x0155; // LATIN SMALL LETTER R WITH ACUTE
$win2utf[0xe1]=0x00e1; // LATIN SMALL LETTER A WITH ACUTE
$win2utf[0xe2]=0x00e2; // LATIN SMALL LETTER A WITH CIRCUMFLEX
$win2utf[0xe3]=0x0103; // LATIN SMALL LETTER A WITH BREVE
$win2utf[0xe4]=0x00e4; // LATIN SMALL LETTER A WITH DIAERESIS
$win2utf[0xe5]=0x013a; // LATIN SMALL LETTER L WITH ACUTE
$win2utf[0xe6]=0x0107; // LATIN SMALL LETTER C WITH ACUTE
$win2utf[0xe7]=0x00e7; // LATIN SMALL LETTER C WITH CEDILLA
$win2utf[0xe8]=0x010d; // LATIN SMALL LETTER C WITH CARON
$win2utf[0xe9]=0x00e9; // LATIN SMALL LETTER E WITH ACUTE
$win2utf[0xea]=0x0119; // LATIN SMALL LETTER E WITH OGONEK
$win2utf[0xeb]=0x00eb; // LATIN SMALL LETTER E WITH DIAERESIS
$win2utf[0xec]=0x011b; // LATIN SMALL LETTER E WITH CARON
$win2utf[0xed]=0x00ed; // LATIN SMALL LETTER I WITH ACUTE
$win2utf[0xee]=0x00ee; // LATIN SMALL LETTER I WITH CIRCUMFLEX
$win2utf[0xef]=0x010f; // LATIN SMALL LETTER D WITH CARON
$win2utf[0xf0]=0x0111; // LATIN SMALL LETTER D WITH STROKE
$win2utf[0xf1]=0x0144; // LATIN SMALL LETTER N WITH ACUTE
$win2utf[0xf2]=0x0148; // LATIN SMALL LETTER N WITH CARON
$win2utf[0xf3]=0x00f3; // LATIN SMALL LETTER O WITH ACUTE
$win2utf[0xf4]=0x00f4; // LATIN SMALL LETTER O WITH CIRCUMFLEX
$win2utf[0xf5]=0x0151; // LATIN SMALL LETTER O WITH DOUBLE ACUTE
$win2utf[0xf6]=0x00f6; // LATIN SMALL LETTER O WITH DIAERESIS
$win2utf[0xf7]=0x00f7; // DIVISION SIGN
$win2utf[0xf8]=0x0159; // LATIN SMALL LETTER R WITH CARON
$win2utf[0xf9]=0x016f; // LATIN SMALL LETTER U WITH RING ABOVE
$win2utf[0xfa]=0x00fa; // LATIN SMALL LETTER U WITH ACUTE
$win2utf[0xfb]=0x0171; // LATIN SMALL LETTER U WITH DOUBLE ACUTE
$win2utf[0xfc]=0x00fc; // LATIN SMALL LETTER U WITH DIAERESIS
$win2utf[0xfd]=0x00fd; // LATIN SMALL LETTER Y WITH ACUTE
$win2utf[0xfe]=0x0163; // LATIN SMALL LETTER T WITH CEDILLA
$win2utf[0xff]=0x02d9; // DOT ABOVE
function Win2utf_encode($str)
{
global $win2utf;
$ret='';
$lastPoint=0;
$point=0;
for($i=0;$i<strlen($str);$i++)
{
$lastPoint=$point;
$point=$win2utf[ord($str[$i])];
// utf8
if ($point<0)
{
user_error('Error while converting from cp1250 to unicode',E_USER_WARNING);
return;
}
else if ($point<= 0x7F)
{
$ret.=chr($point);
}
else if ($point <= 0x7FF)
{
$ret.=chr(0xC0 |(($point>>6) & 0x1F)).chr(0x80 | ($point & 0x3F));
}
else if ($point <= 0xFFFF)
{
if (0xD800 <= $lastPoint && $lastPoint <= 0xDFFF
&& 0xDC00 <= $point && $point <= 0xDFFF)
{
user_error('Error while converting from cp1250 to unicode',E_USER_WARNING);
return;
}
$ret.=chr(0xE0 | (($point>>12) & 0x0F))
.chr(0x80 | (($point>>6) & 0x3F))
.chr(0x80 | ($point & 0x3F));
}
else if ($point <= 0x10FFFF)
{
$ret.=chr(0xF0 | (($point>>18) & 0x07))
.chr(0x80 | (($point>>12) & 0x3F))
.chr(0x80 | (($point>>6) & 0x3F))
.chr(0x80 | ($point & 0x3F));
}
else
{
user_error('Error while converting from cp1250 to unicode',E_USER_WARNING);
}
}
return $ret;
}