Take the 2-minute tour ×

Android App that have a string papà (if I output it, i see: papà).

I send this string to a PHP script encoded as JSON and if I echo this string I read: pap�.

If I see in the database it stored as pap� (obviously).

If I write papà direclty in the database I read papà (obviously).

At this point I'm near sure that the problem is PHP, I tried with htmlentities and in the database I read pap&agrave.

I think you have all information for my problem. Any idea?

Edit to add code:

In Android I have string put in a map:

dati.put("tipo", sottoT);

after do the params for Json

ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    for (Map.Entry<String, String> entry : dati.entrySet()) {
        params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));

        JSONObject json = jsonParser.makeHttpRequest(URL,
            "POST", params);

I send the Json:

 public JSONObject makeHttpRequest(String url, String method,
        List<NameValuePair> params) {

    // Making HTTP request
    try {

        // check for request method
        if(method == "POST"){
            // request method is POST
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params));

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();

In PHP I take the data from POST:

header('Content-type=application/json; charset=utf-8');
$array = array();
    $array[$k] = $v;

$v at this point is already wrong...

PHP Version 5.3.14

share|improve this question
For the htmlentities try you did, please add the code how you tried that. Also please share the exact PHP version you're using. Also please post the JSON string you get from the Android Application. How do you process that JSON string in PHP? Please show that code as well. –  hakre Jan 4 at 20:17
i added code... –  Atomico Jan 5 at 10:32
If $v at that point is already wrong, check the character encoding the POST request comes with. You need to know that. It looks like it is not UTF-8 - but you treat it like. Maybe Windows-1252 or ISO-8859-1? –  hakre Jan 5 at 10:53
i wrote how i did the post in android.. –  Atomico Jan 5 at 11:10
Your Android code tells nothing about the character encoding. Which character encoding are you using for the data processed by that Android code? Please add that to your question. Your PHP version and the (not shown) htmlentities example make me assume that the character encoding is ISO-8859-1. Use that instead of UTF-8 when you process the data in PHP. E.g. does var_dump(utf8_encode($v));show the correct characters? –  hakre Jan 5 at 11:18
add comment

3 Answers

You should specify the encoding in the android code:


Otherwise it will be ISO-8859-1.

On the PHP side, do not do any conversion such as utf8_decode/encode, these will always just make it worse.

Also fix your http header:

share|improve this answer
The constructor UrlEncodedFormEntity(List<NameValuePair>, Charset) is undefined –  Atomico Jan 5 at 11:54
@Atomico ok, how about new UrlEncodedFormEntity(params, "UTF-8") ? Should work according to android docs developer.android.com/reference/org/apache/http/client/entity/… –  Esailija Jan 5 at 11:56
already tried :) –  Atomico Jan 5 at 14:57
@Atomico ok so that's working then, how are you viewing the result? –  Esailija Jan 5 at 15:03
pap�� ... i am going crazy –  Atomico Jan 5 at 18:29
add comment

Why don't you try to transform it into html sign? Like $#numbers;. If not than state encoding like utf-8 general_ci or ANSI. it helped me once.

share|improve this answer
can you explain better pls –  Atomico Jan 5 at 10:30
Well for typing code I use PHP Designer 7, but when I need to change encoding of the code, I use notepad++. It has functions like Encode in UTF-8 of Encode in ANSI. Also you can google all special letters and encode them according to the next exapmle: space is coded as &#32; à is coded as &#224; You can find all of them there: ascii.cl/htmlcodes.htm –  Ivan Jan 5 at 13:40
add comment
up vote 0 down vote accepted

Just for your curiosity... i finally fix the problem. I miss to add th charset the db have to use so i put:
$conn = oci_new_connect($userDb, $pswDB, $urlDb, 'AL32UTF8');
$conn = oci_new_connect($userDb, $pswDB, $urlDb);

So Android have:
httpPost.setEntity(new UrlEncodedFormEntity(params, "utf-8"));
In Php i have:
header('Content-Type: application/json; charset=utf-8'); (don't know if this is important)

This is all..ty all for help

share|improve this answer
add comment

Your Answer


