Strip phone number of all non alpha-numeric characters


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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

You need to login to post a comment.