473,569 Members | 2,436 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_Conten ts($_FILES['Datei']['tmp_name']);
$buffer = utf8_encode($bu ffer);
.....
echo $buffer;
unlink($_FILES['Datei']['tmp_name']);
}

Thanks,
Langi
Jan 9 '07 #1
1 2522
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_enco ding.

--
Andy Hassall :: an**@andyh.co.u k :: 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
1906
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
5035
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 column, ALTER TABLE `icons` CHANGE `name_farsi` `name_farsi` VARCHAR( 99 ) CHARACTER SET utf8 COLLATE utf8_persian_ci DEFAULT NULL and change...
6
3774
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 currency symbol etc. the current csv module cannot handle unicode the docs say, is there any workaround or is unicode support planned for the near...
12
4072
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 mappings though, and it seems like a shortcoming of the .NET framework: When I see Unicode value 0x10400, I'm supposed to map it to value 0x10428....
2
8446
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 character in the given encoding. Line 1, position 1. line highlighted in red = this.LoadLayout(this.GetType (),...
5
1629
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
3917
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 language that is good at parsing text to convert it into a mutt alias file. There are better ways to use Mutt with Mac's addressbook, but I want to be...
7
13040
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, judging by the information given on Google's webmaster helpcenter). The way I test to see if the content is UTF8, is by opening the XML file in...
7
92280
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 want to achieve if I use the code I've found on the web, which is the following: Example of test.txt (save it as UTF8): "éàèüöä" string filePath =...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7679
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5223
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
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.