0

I have a program which does this:

  • Android app, in Java, receives input(in this case, emojis, UTF8)

  • This String is sent to a PHP script via POST

  • The PHP converts all emojis into question marks (?)

I can tell, using Android Logcat, that the java is not ruining it, it is definitely the PHP

The PHP is configured properly, because when I run a test webpage without a post request, which just echoes some emojis (the exact same ones) it works fine

Digital Chris
  • 6,177
  • 1
  • 20
  • 29
Hamzah Malik
  • 2,540
  • 3
  • 28
  • 46
  • 1
    Where are you viewing the output that it looks like question marks? – Digital Chris Oct 31 '14 at 18:49
  • It may be that the full UTF-8 code is still there, but whatever you're using to view the data is not showing UTF-8 characters. – Jonathan M Oct 31 '14 at 18:50
  • @DigitalChris Im using eclipse logcat to view the result of the POST request (for tetsing purpose). The logcat DOES show emojis correctly when Im using Log.d() to view them, so its not the viewer, its certainly the PHP – Hamzah Malik Oct 31 '14 at 18:51
  • 1
    I solved this using the solutions on this thread http://stackoverflow.com/questions/5270591/post-utf-8-encoded-data-to-server-loses-certain-characters – Hamzah Malik Nov 04 '14 at 21:37

2 Answers2

1

I think your best solution is to use Emoji for PHP. It handles all of the conversions for you. Grab a copy at:

http://code.iamcal.com/php/emoji/

Here is a code example:

<?php
    include('emoji.php');


    # browser sniffing tells us that a docomo phone
    # submitted this text

    $clean_text = emoji_docomo_to_unified($_POST[message]);


    ...


    # now we want to show it in a desktop browser

    $html = emoji_unified_to_html($clean_text);
?>
Len_D
  • 1,422
  • 1
  • 12
  • 21
0

We connect android with php server. Then we send and retrieve data using HTTPClient. HTTPPost specifies that our request method is post. The response is stored in HTTPResponse. ‘URL’ is the actual link where JSON is present.

Then we use inputstream to get data into bytes. We need to convert byte-stream to character stream. After that we build String with the help of StringBuilder-from:

http://techlovejump.com/connect-android-with-php-mysql-and-json/