Use a multiline regular expression and loop over all matches:
$source = file_get_contents("MAGFLE_Greenbnk_Caraga.txt");
$matches = [];
preg_match_all("/(9954[0-9]{25}).*(.{13}$)/um", $source, $matches);
for($i = 0; $i < count($matches[1]); ++$i) {
echo "Line {$i} -- ";
echo "chars that start with '9954': {$matches[1][$i]} --- ";
echo "last 13 chars: {$matches[2][$i]} <br>";
}
The regular expression contains two capture groups. The first group matches the 29 characters starting with '6654'. The second one matches the last 13 characters.
The matches array contains 3 arrays:
- The first array contains all matched lines
- The second array contains all matches from the first capture group
- The third array contains all matches from the second capture group
I get the following output when applying your data:
Depending on your data this will not work in all cases. Maybe you have to enhance the regex with more rules.