2

I recently wrote a webservice that runs as a Java application (probably not the best idea, but I'm more fluent in Java than in other languages like PHP or English :p). The Java application simply outputs the JSON data to System.out.

And then I wrote a tiny PHP script that uses the Java application.

Here is my PHP script :

ob_start('ob_gzhandler');
header("Content-Type: application/json; charset=UTF-8");
passthru("java -jar webservice.jar ");

The issue is that every special char (like "é") is output as "??"

Any idea of what I could try to fix that encoding issue ?

Thanks

EDIT : when I run java -jar webservice.jar in a shell, I have no encoding issue

6
  • Is this in the browser or on the command line? Commented Apr 24, 2012 at 18:38
  • In a shell command line I have no encoding issue (edited post to add this fact). In browser (or in my mobile client app) the issue appears, that's why I believe it's related to the php script Commented Apr 24, 2012 at 18:39
  • @Estragon Are you sure the output is actually UTF-8 encoded? What happens when you change the encoding to Latin in your browser? Commented Apr 24, 2012 at 18:48
  • No change when setting another charset :( Commented Apr 24, 2012 at 18:51
  • The PHP manual states, that passthru should be used mainly for binary data output. Try using system() maybe? Commented Apr 24, 2012 at 18:56

3 Answers 3

1

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

Sounds like you need to make sure you are handling the double byte characters correctly :)

More on encoding: http://illegalargumentexception.blogspot.com/2009/05/java-rough-guide-to-character-encoding.html

Sign up to request clarification or add additional context in comments.

Comments

1

I solved my problem by adding -Dfile.encoding=UTF8to my java call :

java -Dfile.encoding=UTF8 -jar webservice.jar

I guess there may be a better solution but it solved my problem so :)

Comments

0

Encoding is a problem that covers a lot of variables: operational system, app, bd etc.

Try to follow this: http://www.phpwact.org/php/i18n/utf-8

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.