假设我有以下字符串:
$string = '很棒的@jason,我想@sally 也会喜欢的。'
我在用着:
$mentions = strstr($string, '@');
echo $mentions
哪个输出
@jason I think @sally would love it too.
期望的输出
@jason @sally
我只是不知道如何在 php 中做到这一点,在 js 中我只是这样做:
hashtags = /\@\w+/g;
var matches = string.match(hashtags);
alert(matches);
php 中的 preg_match() 返回一个布尔值,所以我能得到的最接近的是 strstr()... 但在第一次匹配后返回整个字符串。