, , ...
"You have a problem and you decided to use regular expressions ... now you have two problems."
Your problem can be easily solved if we assume that "test:" is not part of the actual string to be analyzed.
<?php
$in = '002005@1111@333333@;10205@2000@666666@;002005@1111@55555@;';
function splitGroupsAndGetColumn($input, $groupSeparator, $columnSeparator, $columnIndex, $skipEmpty=true)
{
$result = array();
$groups = explode($groupSeparator, $input);
foreach($groups as $group)
{
$columns = explode($columnSeparator, $group);
if (isset($columns[$columnIndex]))
{
array_push($result, $columns[$columnIndex]);
}
else if (! $skipEmpty)
{
array_push($result, NULL);
}
}
return $result;
}
var_dump(splitGroupsAndGetColumn($in, ';', '@', 2));
Conclusion:
array(3) {
[0]=>
string(6) "333333"
[1]=>
string(6) "666666"
[2]=>
string(5) "55555"
}
source
share