0

I know it's a stupid question but I am done experimenting and wasting further time on it. To cut the story short here's what I am battling with:

I have a string $userName = "John \uD83D\uDE0D\uD83D\uDE0D\uD83D\uDE0D";

I have to apply json_decode() on all unicode occurrences in this string like \uD83D, \uDE0D, \uDE0D etc.

I thought I could use some regex based solution. Can you help me get this done.

Ali
  • 5,021
  • 4
  • 26
  • 45
  • can you clarify your question? Why should you use json decode on a string? – Lelio Faieta Jun 21 '18 at 13:52
  • I have to send this string as a push notification to iphone users. And I have to convert those emojis to their symbols. – Ali Jun 21 '18 at 13:53
  • May be I don't have to use json_decode. Can you propose any other solutions? – Ali Jun 21 '18 at 13:54
  • that's ok. I don't get where the json part comes in... – Lelio Faieta Jun 21 '18 at 13:54
  • 1
    Where did you get the string from in the first place? Was it proper JSON at some point? – deceze Jun 21 '18 at 13:55
  • that string is the username (along with emojis) stored in mysql database. – Ali Jun 21 '18 at 13:56
  • it's simply a varchar data type and has exactly the same string value as written in the question above – Ali Jun 21 '18 at 13:57
  • 1
    And how did it sprout its unicode escape sequences? – deceze Jun 21 '18 at 13:57
  • Users get themselves registered through iphone app, and they can add emojis to their names. That's how these unicode characters get in to the database. – Ali Jun 21 '18 at 13:58
  • 1
    You need to fix something in that registration process then. The database should store the raw emoji Unicode characters, not their escape sequences. – deceze Jun 21 '18 at 14:01
  • Right, but that's not in my hand now. I just have to fix this. When I did `json_decode("\uD83D")` then I get the proper emoji in push notification. – Ali Jun 21 '18 at 14:03
  • 1
    Well, see the duplicate. This'll do: https://stackoverflow.com/a/27975110/476 – deceze Jun 21 '18 at 14:08
  • Great, that did the trick. Thanks a lot deceze. – Ali Jun 21 '18 at 14:10
  • Actually I already tried accepted answer, it didn't work. This time I tried masakielastic's answer and it worked like a charm. Thanks for pointing me to it again. – Ali Jun 21 '18 at 14:14

0 Answers0