-2

How would I take a text string with emojis and wrap each emoji in an HTML tag?

Example string...

str = "This is  a test with  emojis in the  string"

Desired output...

output = "This is <i></i> a test with <i></i> emojis in the <i></i> string"
CinCout
  • 9,486
  • 12
  • 49
  • 67
Shpigford
  • 24,748
  • 58
  • 163
  • 252
  • 1
    This may help https://stackoverflow.com/questions/45306245/php-extract-emoji-from-a-string, but it's not an answer to your exact question – GrumpyCrouton Dec 14 '18 at 17:02
  • 1
    @GrumpyCrouton I think with that question it can be extracted so easily it is a dup. https://3v4l.org/KZbbZ (unless there are emojis missing from that character list) – user3783243 Dec 14 '18 at 17:19
  • @user3783243 I would agree – GrumpyCrouton Dec 14 '18 at 17:22
  • https://stackoverflow.com/q/24840667/2191572 and https://github.com/mathiasbynens/emoji-regex are probably the correct answer. Not quite sure that emoji regex needs a special post for PHP. – MonkeyZeus Dec 14 '18 at 17:33

1 Answers1

-1

This regex will match emojis:

[\{uD83C}-\x{DBFF}\x{DC00}-\x{DFFF}]+

Replace with:

<i>$0</i>

Demo: https://regex101.com/r/aGfJil/1/

Ibrahim
  • 6,006
  • 3
  • 39
  • 50