- preg_match_all: documentation ( source)
- var_export: documentation ( source)
<?php
$strings = [
"21-114512",
"test12345abcd",
"12test123456testing",
"123456",
"1234",
"12345a67890"
];
function extract_numbers($string)
{
return preg_match_all('/(?<!\d)\d{5,6}(?!\d)/', $string, $match) ? $match[0] : [];
}
foreach ($strings as $string) {
var_export(extract_numbers($string));
echo "\n---\n";
}