- substr_count: documentation ( source)
- preg_match_all: documentation ( source)
- implode: documentation ( source)
- str_replace: documentation ( source)
<?php
$data = '
39 9
30 30 30 31 34 30 30 32 33 32 36 30 31 38 0D 0A 00014002326018..
39 30 30 30 31 34 30 30 32 33 32 36 30 35 34 0D 900014002326054.
0A .
39 30 30 30 31 34 30 30 32 33 32 36 30 39 31 0D 900014002326091.
0A .
39 30 30 30 31 34 30 30 32 33 32 36 31 36 33 0D 900014002326163.
0A .
39 9
30 30 30 31 34 30 30 32 33 000140023
32 36 32 30 30 0D 0A 26200..
39 9
30 30 30 31 34 30 30 32 33 32 36 32 30 30 0D 0A 00014002326200..
39 30 30 30 31 34 30 30 32 33 32 36 31 32 32 0D 900014002326122.
0A .
39 9
30 30 30 31 34 30 30 32 33 000140023
32 36 31 35 34 0D 0A 26154..
39 30 30 30 31 34 30 30 32 33 9000140023
32 36 31 33 31 0D 0A 26131..
39 9
30 30 30 31 34 30 30 32 33 000140023
32 36 31 30 34 0D 0A 26104..
39 30 30 30 31 34 30 30 32 33 32 36 30 39 30 0D 900014002326090.
0A .
39 30 30 30 31 34 30 30 32 33 32 36 31 39 37 0D 900014002326197.
0A .
39 9
30 30 30 31 34 30 30 32 33 32 36 32 30 38 0D 0A 00014002326208..
39 30 30 30 31 34 30 30 32 33 9000140023
32 36 31 31 35 0D 0A 26115..
39 9
30 30 30 31 34 30 30 32 33 000140023
32 36 31 36 34 0D 0A 26164..
39 9
30 30 30 31 34 30 30 32 33 000140023
32 36 30 31 36 0D 0A 39 30 30 30 31 34 30 30 32 26016..900014002
33 3
32 36 32 34 36 0D 0A 26246..
39 9
30 30 30 31 34 30 30 32 33 000140023
32 36 32 34 36 0D 0A 26246..
39 9
30 30 30 31 34 30 30 32 33 000140023
32 36 30 37 39 0D 0A 26079..
39 9
30 30 30 31 34 30 30 32 33 000140023
32 36 31 32 30 0D 0A 26120..
39 9
30 30 30 31 34 30 30 32 33 32 36 32 32 38 0D 0A 00014002326228..
39 30 30 30 31 34 30 30 32 33 9000140023
32 36 31 38 36 0D 0A 26186..';
$pattern = '/(?:^.{48}|\.)([0-9]+\.?)/m';
preg_match_all($pattern, $data, $tags);
//join all the bits belonging to the number
$data=implode("", $tags[1]);
//count the dots to have a correct count of the numbers grabbed
//since each number was grabbed with an ending dot initially
$count=substr_count($data, ".");
//replace the dots with a html <br> tag (avoiding a split and a foreach loop)
$tags=str_replace('.', "<br>\n", $data);
print $tags . "<br>\n" . $count . " total scanned";
?>