FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP utf-8 to Java Applet





Peterssidan
I want to transfer uft-8 strings to a java applet. The problem with Java is that it's not using utf-8. I think it's utf-16. I have tried to send the string as a parameter and receive it with the getParameter method but it goes wrong for some characters because the encoding is not he same.

I don't think it's easy to translate back inside java because it has already interpret the parameter as an utf-16 string, but if it's possible to do it from java I prefer that.

Php handles the data on the server but can't translate uft-8 to utf-16 as far as I know. Anyone know a script for this? I must have full unicode support with all characters.

Am I trapped here? Is there anything I can do?
rohan2kool
PHP falls short when it comes to handling unicode streams... an external library may help you: http://labs.centralnic.com/Unicode.php
Peterssidan
It has gone a while now so I have found a solution.
Code:
      // url is an URL object
      InputStream in = url.openStream();
            
      BufferedReader bf = new BufferedReader(new InputStreamReader(in, "UTF8"));

Note, the code above is not complete. As you see I don't use the parameters to send the data to the Applet. Instead the Applet can call a page to get the data. In the InputStreamReader constructor I specify that the content to read is UTF-8. Now I have a BufferedReader that is easy to read from Very Happy
assailant
Peterssidan wrote:
It has gone a while now so I have found a solution.
Code:
      // url is an URL object
      InputStream in = url.openStream();
            
      BufferedReader bf = new BufferedReader(new InputStreamReader(in, "UTF8"));

Note, the code above is not complete. As you see I don't use the parameters to send the data to the Applet. Instead the Applet can call a page to get the data. In the InputStreamReader constructor I specify that the content to read is UTF-8. Now I have a BufferedReader that is easy to read from Very Happy


Firstly, what does this have to do with PHP? The best i can assume is that the 'url' in the above code snippet is a url to your site, which is written and generated using PHP.

Given that, your web application basically gives out a stream of bytes, which could very well be a binary stream. Even then Java can still interpret it as an UTF-8 stream, because there is no way of knowing which encoding was really intended [this however is managed by using a content-encoding header]. Which is why, while generating the page from your web application, php needs to have Unicode support.

As for Java, it has Native Unicode support and you don't have to deal with anything much there.
Peterssidan
It doesn't have much to do with PHP except that I'm using UTF-8 for PHP on the server and therefore my data is in UTF-8. I will not use any third part server for this if that was what you thought. As I said earlier the problem is solved so I guess this topic has reach its end.
Related topics
Which script language do you like most?
Switching to UTF-8
utf-8 cMS
java applet not working!!
JavaScript or Java Applet and maybe DHTML codes
java applet refresh problem
games using java applet
Converter banco de dados para UTF-8
PhpMyAdmin and UTF-8
My java applet can not find class file on the server
Bases de datos UTF-8
UTF-8 from MySQL to PHP
Java Applet
search, a bit contextual in php
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.