Blondy314
Blondy314

Reputation: 761

Converting from Windows-1255 to UTF-8 encoding in Objective-C or PHP

I am developing an iPhone app in Xcode which brings data from the SQL database of a Hebrew-language web site. This database uses Windows-1255 encoding for all of its tables. When I pull data from this database to my app, it shows up as gibberish, so I think it's not being translated from the Windows-1255 encoding to the UTF-8 encoding that I want to use for data in my app.

How can I convert the data to UTF-8 in Xcode? Can I add something to the query so that the database itself will send data already translated to UTF-8 instead of sending me data encoded in Windows-1255?

Upvotes: 1

Views: 1900

Answers (3)

Ahoura Ghotbi
Ahoura Ghotbi

Reputation: 2896

For PHP you can use this function : http://php.net/manual/en/function.mysql-set-charset.php

Note you need to do this right after you connect to your database.

Upvotes: 0

Scott Little
Scott Little

Reputation: 1939

I'm assuming that you are receiving this data as an `NSData' type. What you need to do is use the method:

- (id)initWithBytes:(const void *)bytes length:(NSUInteger)length encoding:(NSStringEncoding)encoding

on NSString. Get the bytes from the data and pass that as the bytes. The only thing is I don't really see an encoding type for 1255 - the list is here.

Hope that helps

Upvotes: 1

Jakub Matczak
Jakub Matczak

Reputation: 15676

Try iconv PHP function. It always worked perfectly for me.

Upvotes: 0

Related Questions