Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何仅获取@symbol后面的用户名_Php_Preg Match - Fatal编程技术网

Php 如何仅获取@symbol后面的用户名

Php 如何仅获取@symbol后面的用户名,php,preg-match,Php,Preg Match,我有这个代码,它完全符合我的要求。 然而,它只为一个用户名,我想知道我如何才能做到这一点,使它得到多个用户名从它 $string = 'Tweet @one two @three four'; preg_match("/@(\\w+)/", $string, $matches); $hash1 = $matches[1]; echo $hash1; $hash1返回“一”。使用 preg\u match\u all 请看这里使用功能: $string = 'Tweet @one two @th

我有这个代码,它完全符合我的要求。 然而,它只为一个用户名,我想知道我如何才能做到这一点,使它得到多个用户名从它

$string = 'Tweet @one two @three four';
preg_match("/@(\\w+)/", $string, $matches);
$hash1 = $matches[1];
echo $hash1;
$hash1返回“一”。

使用

preg\u match\u all

请看这里使用功能:

$string = 'Tweet @one two @three four';
preg_match_all("/@(\w+)\b/", $string, $matches, PREG_SET_ORDER);
print_r($matches);