We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

dbug13 on 08/13/08


Tagged

regex php textmate


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

sumandahal
luman


Strip phone number of all non alpha-numeric characters


Published in: PHP 


  1. <?php
  2.  
  3. /**
  4.  * Strip a Phone number of all non alphanumeric characters
  5.  */
  6. $phone = "+1(555)-555-1212";
  7. $phone = preg_replace('/(\W*)/', '', $phone);
  8. print $phone;
  9.  
  10. // Result: 15555551212
  11.  
  12. ?>

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: Scooter on August 16, 2008

What if the phone number contains an extension? e.g. +1 (555) 555-1212 ext. 228

You need to login to post a comment.