Milad ranjbar Milad ranjbar - 3 years ago 156
PHP Question

php extract Emoji from a string

I have a string contain emoji.
I want extract emoji's from that string,i'm using below code but it doesn't what i want.


        
Answer Source

Try looking at preg_match_all function. preg_match stops looking after it finds the first match, which is why you're only ever getting the first emoji back.

Taken from this answer:

preg_match stops looking after the first match. preg_match_all, on the other hand, continues to look until it finishes processing the entire string. Once match is found, it uses the remainder of the string to try and apply another match.

http://php.net/manual/en/function.preg-match-all.php

So your code would become:

$string = "
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download