take out dashes from telephone

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

take out dashes from telephone

Post by gurjit »

Hi all,

i have a field with mixed telephone formats i need to takeout the

- dashes
- any alpha characters
- align the number to the left with dashes and spaces taken out

how can i do this using preg_replace.

I tried this but it never worked

Code: Select all

<?php
preg_replace( "%[^0-9]%", "", $TELEPHONE );
?>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

$phone = preg_replace("/[^0-9]/", "", $phone);
Post Reply