title: Special characters between Android application and PHP script
body: <p>I want to get some text from a PHP page into an Android application. As long as the characters are ASCII (up to 128) there's no problem but when I want to display special characters like 'Ţ', 'Â' (the so called Latin-1 Supplement and/or Latin Extended-A - see it at <a href="http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000">Unicode Chart</a>)
  I get weird symbols into my Android application (�).</p>
  
  <p>The problem is that my Android application cannot handle characters from Latin-1 Supplement (which PHP can) but characters from the Latin Extended-A charset (which PHP cannot). I don't know what common charset for both languages to use because the one that Java is able to read PHP is not, and vice versa.</p>
  
  <p>My Java function that gets the content of the PHP page is this:</p>
  
  <pre><code>public static String GetData() {
      byte[] Bresult = null;
      HttpClient client = new DefaultHttpClient();
      HttpPost post = new HttpPost("http://www.mypage.com/script.php");
      try {
          List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(1);
          nameValuePairs.add(new BasicNameValuePair("var", "val"));
          post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
          HttpResponse response = client.execute(post);
          StatusLine statusLine = response.getStatusLine();
          if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){
              Bresult = EntityUtils.toByteArray(response.getEntity());
              Result = new String(Bresult, "UTF-8");
          }
      } catch (UnsupportedEncodingException e) {
          Log.w("MYAPP", "Unsupported Encoding Exception (" + e.getMessage() + ")");
      } catch (Exception e) {
          Log.w("MYAPP", "Exception (" + e.getMessage() + ") ocurred");
      }
      return Result;
  }
  </code></pre>
  
  <p>So, this code gives me the content of the <em>script.php</em> page. If the characters of the text received are from 0 to 128 there is no problem. Elsewhere, I get weird characters.</p>
  
  <p>Now, this is my PHP code:</p>
  
  <pre><code>&lt;?php
      header("Content-Type: text/plain;charset=utf-8");
      echo "ÂŞÂĂĒ";
  ?&gt;
  </code></pre>
  
  <p>I also have a C++ application and it does read the text correctly. I have been trying a lot of methods all the day and I just don't get it. Who, where, why?
  Thanks.</p>