Convert windows-1255 to UTF-8 in PHP 5

I have a page on my website that gets the main content from the old mainframe. Mainframe content encoding is windows-1255 (Hebrew). The coding of my site is UTF-8.

At first I used an iframe to display the received response from the mainframe. In this solution, I had no problems setting the page encoding, and the character display was fine, but I had problems displaying the page in response (my entire site is reacting).

Then I tried to get the contents using file_get_contents and add it to the right place, but all the characters look like this: then I converted the contents:

 iconv("cp1255","UTF-8",file_get_contents("my_url")); 

The result of this was canceled in Hebrew. For example, the word "nice" appears as "ecin". The content also includes HTML tags, not just Hebrew text, so I can't just cancel the text with hebrev .

I saw that in PHP 4 there is a function fribidi_log2vis which seems to solve my problem, but it is not supported in PHP 5 (I'm working with PHP 5.3.3).

Is there a better way to handle it than loading content in an iframe?

UPDATE

I tried to get the test file that I created (with windows-1255 encoding) and my source code is working fine. I suspect that the content I receive is not 1255 windows, at least not in the order of the Hebrew letters. The reason may be a conversion on the mainframe. I will have to study this (I have to wait until Sunday, because I do not have direct access to the server).

+6
source share
1 answer

The problem is that file_get_contents receives content with ISO 8859-1 as character encoding. You must create a stream context using the stream_context_create function with Windows-1255 encoding for file_get_contents:

 $opts = array('http' => array('header' => 'Accept-Charset: windows-1255,utf-8;q=0.7,*;q=0.7')); $context = stream_context_create($opts); $content = file_get_contents('my_url', false, $context); iconv("cp1255", "UTF-8", $content); 
+1
source

All Articles