有点 PHP 和 Regex 菜鸟,我从 Web 服务收到以下信息:
test:002005@1111@333333@;10205@2000@666666@;002005@1111@55555@;
上面一行是一个由 3 个数字组成的序列,重复 3 次。我想获得每个序列的第 3 个数字,我相信最好的类(class)(除了 3000 次爆炸)是 preg_match_all,但我很难全神贯注于 RegEx。
最终结果应该是这样的:
Array
(
[0] => 333333
[1] => 666666
[2] => 55555
)
在此先感谢您的帮助。
最佳答案
if(preg_match_all('/.*?(?:\d+@){2}(\d+)@;/',$s,$m)) {
print_r($m[1]);
}
或
你可以使用 explode 作为:
$input = rtrim($input,';');
$temp1 = explode(';',$input);
foreach($temp1 as $val1) {
$temp2 = explode('@',$val1);
$result[] = $temp2[2];
}
print_r($result);
关于php - 在 PHP 中将数字序列转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10532826/