php extract Emoji from a string

2019-02-19 05:05发布

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.

$string = "                

1条回答
2楼-- · 2019-02-19 05:29

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 = "                                                                    
查看更多
登录 后发表回答