Вариант №1
1 |
$phone = preg_replace("/[^0-9]/", '', $phone); |
Вариант №2
1 2 3 4 5 |
const PHONE_PATTERN = ["+", "-", "(", ")", " "]; function getPhone($phone) { return str_replace(PHONE_PATTERN, null, $phone); } |
Вариант №3
1 2 3 4 5 6 7 |
function phone($str) { if (!preg_match('/^[\d-]+$/', $str)) { $str = preg_replace('/[^\d]+/', '', $str); } return $str; } |