Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Convert Windows-1256 encoded text to UTF-8

I am getting Windows-1256 encoded text from the web and nee to convert it to utf-8.

I tried using mb_convert_encoding and iconv but they don't seem to work.

none of them seem to be capable of handling windows-1256.

How to do it?

Edit: More details about the errors. When trying

mb_convert_encoding($text,"utf-8", "windows-1256");

I get

Message: mb_convert_encoding() [function.mb-convert-encoding]: Illegal character encoding specified

And when i try

iconv("windows-1256", "utf-8", $text);

I get no errors but it returns an empty string

like image 336
applechief Avatar asked Dec 21 '11 16:12

applechief


2 Answers

Trying

echo iconv('WINDOWS-1256', 'UTF-8', 'testÍÊ');

...on http://writecodeonline.com/php/ seems to work correctly (produces testأچأٹ)

like image 140
Frosty Z Avatar answered Sep 20 '22 13:09

Frosty Z


Try this, should work:

iconv("windows-1256", "utf-8//TRANSLIT//IGNORE", $text)

like image 42
Abdelhakim Avatar answered Sep 18 '22 13:09

Abdelhakim