Estragon
Estragon

Reputation: 1462

PHP and Java encoding issues

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

Upvotes: 2

Views: 871

Answers (3)

Estragon
Estragon

Reputation: 1462

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 :)

Upvotes: 1

user1352498
user1352498

Reputation:

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

Upvotes: 0

Brandt Solovij
Brandt Solovij

Reputation: 2134

<%@ 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

Upvotes: 1

Related Questions