2013-07-26 155 views
0

我有这样的:我怎样才能让preg_match_all阵列

$text = $_POST['text']; 

当我echo $text我得到这个:

ggg #hhh #ddd ggg hhhrr ggg #ttt 

当我这样做:

$val = preg_match_all("/#\w+/", $text, $matches); 
print_r($matches); 

我得到

Array ([0] => Array ([0] => #hhh [1] => #ddd [2] => #ttt)) 

但我想这样的输出:

print_r($matches); 

要这样:

Array ([0] => #hhh [1] => #ddd [2] => #ttt) 

感谢

回答

0

改变这种以从数组的第一个(零)项目

print_r($matches[0]); 
1

另一种方法是使用命名组。

$val = preg_match_all("/(?P<myLabel>#\w+)/", $text, $matches); 
print_r($matches['myLabel']);