-3

How to remove ⭕️ and ♛ emoji from the beginning of the string PHP? Please note that I only want to remove ⭕️ and ♛ emoji, NOT all the emoji.

For example:-

If the string is ⭕️ ABC 123 XYZ 789 then it should look ABC 123 XYZ 789 after removal of emoji ♛ from the beginning of the string.

I tried preg_replace("⭕️", "", $string) and str_replace("⭕️", "", $string) but does not work at all.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
erbhaveshkumar
  • 35
  • 1
  • 1
  • 4

2 Answers2

3

There is no need for regex here, just use ltrim():

$str = '⭕️ and ♛ emoji from t';
var_dump(ltrim($str, '⭕️♛'));

Result:

string(21) " and ♛ emoji from t"

An example.

jeroen
  • 91,079
  • 21
  • 114
  • 132
-1

Looks to already be answered here: PHP : writing a simple removeEmoji function

Because its just those two emojis, you only have to search on those two unicodes ( U+265B and U+2B55) just do a replace on those characters instead of a whole regex.

Jeremy
  • 24
  • 5
  • 1
    shouldn't you have flagged as a possible duplicate instead? You're plagiarizing on an existing Q&A. – Funk Forty Niner Apr 11 '18 at 19:26
  • @WiktorStribiżew so that gives them the right for plagia? come on; I think you should know about this. You've been here long enough. Edit: you deleted that comment I was responding to. – Funk Forty Niner Apr 11 '18 at 19:29
  • @FunkFortyNiner sorry to of offended, was not my intent. Kind of harsh though, as I just now noticed i have the ability to flag posts for duplicate now. I didn't have those rep points < hour ago... – Jeremy Apr 11 '18 at 19:55
  • No offense taken. But what do you mean by "harsh"? That isn't my downvote you received btw. – Funk Forty Niner Apr 11 '18 at 20:10