Error when transcoding from UTF16 to UTF8 with utf8_encode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthias Langbein

    Error when transcoding from UTF16 to UTF8 with utf8_encode

    Hi all,

    when i convert a uploaded file to UTF-8 with the utf8_encode function,
    the string is prefixed by the two characters

    ÿþ

    The file is originally encoded as UTF-16. Can anybody tell me, why
    this happens?

    Code:

    if (isset($_FILES['Datei']) and !$_FILES['Datei']['error']) {
    $buffer = file_get_Conten ts($_FILES['Datei']['tmp_name']);
    $buffer = utf8_encode($bu ffer);
    .....
    echo $buffer;
    unlink($_FILES['Datei']['tmp_name']);
    }

    Thanks,
    Langi
  • Andy Hassall

    #2
    Re: Error when transcoding from UTF16 to UTF8 with utf8_encode

    On Tue, 09 Jan 2007 01:14:28 +0100, Matthias Langbein
    <matthias_langb ein@web.dewrote :
    >when i convert a uploaded file to UTF-8 with the utf8_encode function,
    >the string is prefixed by the two characters
    >
    >ÿþ
    That appears to be a Unicode BOM:


    However, it's a UTF-16 big-endian Unicode BOM, and should presumably have been
    converted into EF BB BF, the UTF-8 representation, or stripped off.
    >The file is originally encoded as UTF-16. Can anybody tell me, why
    >this happens?
    The utf8_encode function can't convert from UTF-16; it only does ISO-8859-1.
    Perhaps you need one of the mbstring functions, such as mb_convert_enco ding.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    Working...