Code Monkey home page Code Monkey logo

Comments (13)

iamcal avatar iamcal commented on July 23, 2024 4

Oh, iPhones (since iOS) now use unified emoji, so you really want:

"\xF0\x9F\x98\x84 Vei na..."

Which is codepoint U+1F604

from php-emoji.

iamcal avatar iamcal commented on July 23, 2024 3

It's as simple as using double quotes:

$body['aps'] = array('alert' => "\xf0\x9f\x98\x84", 'sound' => 'default');

After calling json_encode() on that, you'll get:

{"aps":{"alert":"\ud83d\ude04","sound":"default"}}

...which is correct JavaScript unicode escaping.

from php-emoji.

iamcal avatar iamcal commented on July 23, 2024

That's not how you escape UTF-8 in PHP. Try this:

"\xEE\x90\x95 Vei na..."

You can find the UTF-8 bytes for a codepoint using this: http://unicodey.com/?cp=e415

from php-emoji.

phmarques avatar phmarques commented on July 23, 2024

Cal, can you explain it with more details, please?

from php-emoji.

iamcal avatar iamcal commented on July 23, 2024
  1. How are you sending the message to APN? Using what language and what code?
  2. iOS no longer uses \ue415 - you should be using \u1f604

from php-emoji.

alexleandrom avatar alexleandrom commented on July 23, 2024

We try to send emoji from php webservice.
We using this Lib to send on php
https://github.com/duccio/ApnsPHP

from php-emoji.

iamcal avatar iamcal commented on July 23, 2024

It looks like ApnsPHP does some special handling for Unicode. Try this:

$message->setText("Emoji: \\uD83D\\uDE04");

Apns expects 4-nibble \u escapes with a literal slash. To encode an emoji like U+1f604 you need to split it into two surrogate pair codepoints. I used the calculator here: http://www.russellcottrell.com/greek/utilities/SurrogatePairCalculator.htm

from php-emoji.

vikmalhotra avatar vikmalhotra commented on July 23, 2024

I am trying to send push notifications with emoji using php. For sending push notifications, I started with this tutorial and have got the push notifications working.
For sending emoji in push notifications from my php server, I tried with following code snippets, but all I keep getting in the notification is the Unicode characters as it is.

Here are some code snippets I tried...

$body['aps'] = array('alert' => '\xe2\x98\x81 Check', 'sound' => 'default');
$body['aps'] = array('alert' => emoji_unified_to_softbank('\xe2\x98\x81 Check'), 'sound' => 'default');
$body['aps'] = array('alert' => emoji_softbank_to_unified('\xe2\x98\x81 Check'), 'sound' => 'default');

What I should be getting here is a cloud emoji followed by the string 'Check'. But what I get is simply the string, \xe2\x98\x81 Check. I saw that the message looks like this in the payload (I am using json_encode to convert the payload that is a php array, to json encoded format):

\\xe2\\x98\\x81 Check

The reason could be that the payload has to be converted from php array to json-encoded format.
$payload = json_encode($body);

What am I doing wrong here? Can somebody help me out with this?

from php-emoji.

alexleandrom avatar alexleandrom commented on July 23, 2024

Hi dudu I try a lot of tutoriais, but the only step which works is change mysql encoding: Try this:
http://mathiasbynens.be/notes/mysql-utf8mb4

from php-emoji.

vikmalhotra avatar vikmalhotra commented on July 23, 2024

Hi alex, I did not make use of mysql anywhere. The emoji code is hard-coded into the payload in php code.

from php-emoji.

iamcal avatar iamcal commented on July 23, 2024

vikkun: it all depends on the library doing the push notifications. Apple wants to recieve JSON looking like this:

"body" : "\u2601"

so try the following PHP:

$body['aps'] = array('alert' => '\\u2601');

from php-emoji.

vikmalhotra avatar vikmalhotra commented on July 23, 2024

iamcal: After referring your earlier comment, I am trying to use the unified emoji codes. But \\u2601 did not work either.
Here is my gist of what I am trying to do. It seems that since I am json encoding my payload, escaping the slash does not work.

// Create the payload body - emoji for smiling face with open mouth and smiling eyes
$body['aps'] = array('alert' => '\xf0\x9f\x98\x84', 'sound' => 'default');

// THIS IS WHAT SEEMS TO BE CAUSING THE EMOJI CODE TO APPEAR AS IT IS ON iPhone
$payload = json_encode($body);

Is there some workaround to this situation?

from php-emoji.

 avatar commented on July 23, 2024

Does emoji works with APNS Java code? If yes, could you please share code snippet ?

from php-emoji.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.