Xan*_*der 3 php regex arrays string preg-match-all
有点在PHP和Regex中的noobie,我从Web服务收到以下内容:
test:002005@1111@333333@;10205@2000@666666@;002005@1111@55555@;
Run Code Online (Sandbox Code Playgroud)
上面的行是3个数字的序列,重复3次.我想获得每个序列的第3个数字,我相信最好的课程(除了3000次爆炸)将是preg_match_all但我在艰难的时间环绕着RegEx.
最终结果应如下所示:
Array
(
[0] => 333333
[1] => 666666
[2] => 55555
)
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助.
if(preg_match_all('/.*?(?:\d+@){2}(\d+)@;/',$s,$m)) {
print_r($m[1]);
}
Run Code Online (Sandbox Code Playgroud)
要么
你可以使用explode来做到:
$input = rtrim($input,';');
$temp1 = explode(';',$input);
foreach($temp1 as $val1) {
$temp2 = explode('@',$val1);
$result[] = $temp2[2];
}
print_r($result);
Run Code Online (Sandbox Code Playgroud)