Another RegExp question (extracting telephone numbers)
Posted: Mon Jan 24, 2005 3:22 pm
Hello together,
I'm trying to extract telephone numbers and have a "small" problem.
2 examples:
Telefon: 07128/12345 - 0 Telefax: 07128/12345
| |
------------------
|
07128123450
Telefon: ++49 (7128) 12345 - 0 - Fax: 07128/12345
| |
-------------------------
|
497128123450
}
This would output me
071281234500712812345
=> Oops, not exactly what I want, since my pattern just takes all digits. It gives me telephone and telefax number. But I really just want the telephone number! How can I improve my RegExp?
Thanks a lot!
I'm trying to extract telephone numbers and have a "small" problem.
2 examples:
Telefon: 07128/12345 - 0 Telefax: 07128/12345
| |
------------------
|
07128123450
Telefon: ++49 (7128) 12345 - 0 - Fax: 07128/12345
| |
-------------------------
|
497128123450
Code: Select all
if (preg_match("/(telefon|tel\.|fon|telephone|telefonnr\.|telefonnummer)/i", $value))
{
$pattern = "/\D+/i";
$replacement = "";
$strTelefonnummer = preg_replace($pattern, $replacement, $value);
echo "<strong>Telefon : ".$strTelefonnummer."</strong><br>";}
This would output me
071281234500712812345
=> Oops, not exactly what I want, since my pattern just takes all digits. It gives me telephone and telefax number. But I really just want the telephone number! How can I improve my RegExp?
Thanks a lot!