Forum Moderators: coopster
where does the data come from? It must be generated with some consistency if it comes from a single source, if it is from multiple sources then you may need a pattern per source.
once you can identify the pattern then you can make decisions on how to best extract it
<?php
$str = '1234567 str 999999999586 390 joe smith popopopopopopopopo ';
$str .= '1923892 baltimore, md 787878 1234568 8586552895 1234569';if (preg_match_all("/[^\d]+(\d{7})[^\d]+/si", $str, $extract, PREG_SET_ORDER))
{
foreach ($extract as $number)
{
$extratctedNumbers[] = $number[1];
}
}var_dump($str);
die(var_dump($extratctedNumbers));
?>
but. this not extract numbers in the extrems!
<?phpthis is OK I think...
$str = '1234567 str 999999999586 390 joe smith popopopopopopopopo ';
$str .= '1923892 baltimore, md 787878 1234568 8586552895 1234569';if (preg_match_all("/(\d+)/si", $str, $extract, PREG_SET_ORDER))
{
foreach ($extract as $number)
{
if (strlen($number[1]) == 7)
$extratctedNumbers[] = $number[1];
}
}var_dump($str);
die(var_dump($extratctedNumbers));
?>