1
<?php
$string = "String is '@Name Surname test @Secondname Surname tomas poas tomas'"
preg_match_all("/@(\w+)(\s)(\w+)/", $string, $matches);
[
0 => '@Name Surname',
1 => '@Secondname Surname',
]
我得到什麼;
array (
0 =>
array (
0 => '@Name Surname',
1 => '@Secondname Surname',
),
1 =>
array (
0 => 'Name',
1 => 'Secondname',
),
2 =>
array (
0 => ' ',
1 => ' ',
),
3 =>
array (
0 => 'Surname',
1 => 'Surname',
),
)
這就是'preg_match_all()'的工作原理。 1 subArray =整個匹配,2subArray 1捕獲組,3subArray 2捕獲組,... – Rizier123