note 89998 deleted from function.preg-match-all by thiago
| From: | thiago@php.net | Date: | Wed, 01 Apr 2009 12:00:10 +0000 |
| Subject: | note 89998 deleted from function.preg-match-all by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152693@lists.php.net to get a copy of this message | ||
Note Submitter: admin (ad) djokodonev.com
----
i have made up a simple function to extract a number from a string..
I am not sure how good it is, but it works.
It gets only the numbers 0-9, the "-", " ", "(", ")",
"."
characters.. This is as far as I know the most widely used characters for a Phone number.
function clean_phone_number($phone) {
if (!empty($phone)) {
//var_dump($phone);
preg_match_all('/[0-9\(\)+.\- ]/s', $phone, $cleaned);
foreach($cleaned[0] as $k=>$v) {
$ready .= $v;
}
var_dump($ready);
die;
if (mb_strlen($cleaned) > 4 && mb_strlen($cleaned) <=25) {
return $cleaned;
}
else {
return false;
}
}
return false;
}