473,508 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Contents($_FILES['Datei']['tmp_name']);
$buffer = utf8_encode($buffer);
.....
echo $buffer;
unlink($_FILES['Datei']['tmp_name']);
}

Thanks,
Langi
Jan 9 '07 #1
1 2519
On Tue, 09 Jan 2007 01:14:28 +0100, Matthias Langbein
<ma***************@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:
http://unicode.org/unicode/faq/utf_bom.html#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_encoding.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jan 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1899
by: Hardkmel | last post by:
hi people, i have a script : <? $num=0; $backendURL = "http://rezo.net/backend/afp"; $limit = 1; // nombre maxi de news à afficher. $file = fopen( $backendURL, "r");
4
5034
by: sinasalek | last post by:
i have a problem with MySQL 4.1.x and UTF8. in version 4.0, i'm using html forms with utf8 charset for inserting unicode strings. but in version 4.1.x it is not working! if i change the charset of...
6
3760
by: Chris | last post by:
hi, to convert excel files via csv to xml or whatever I frequently use the csv module which is really nice for quick scripts. problem are of course non ascii characters like german umlauts, EURO...
12
4049
by: Chris Mullins | last post by:
I'm implementing RFC 3491 in .NET, and running into a strange issue. Step 1 of RFC 3491 is performing a set of mappings dicated by tables B.1 and B.2. I'm having trouble with the following...
2
8440
by: Anna Carr | last post by:
I had a project which was working until this morning and I keep getting the following error. Does anyone know what has happened and how I can fix it?? error message - There is an invalid...
5
1623
by: news.fe.internet.bosch.com | last post by:
Hi , I wanted information about UTF16 format and what is disadvantage over UTF8 format.. TIA Mohan
4
3908
by: R Wood | last post by:
Greetings - A recent Perl experiment hasn't turned out so well, which has piqued my interest in Python. The project is this: take a Vcard file exported from Apple's Addressbook and use a...
7
13016
by: amygdala | last post by:
Hi, I'm trying to let PHP write a 'sitemap.xml' sitemap for Google and other searchengines. It's working, except that the content in the XML file doesn't seem to be UTF8. (Which it should be,...
7
92216
by: firepol | last post by:
Hello there, I am dealing with files encoded in UTF8 and I can't find a way to convert them into ANSI. I've already searched in google for this since a while, and I'm not achieving the result I...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.