nikefido Posted June 4, 2008 Share Posted June 4, 2008 I need some regex to replace characters you'd find in a phone number, such as spaces, periods, dashes, slashes. Can anyone help me get started with some regex? Link to comment https://forums.phpfreaks.com/topic/108727-preg_replace-characters-in-a-phone-number/ Share on other sites More sharing options...
effigy Posted June 4, 2008 Share Posted June 4, 2008 What do you want the final result to be? Numbers only? Link to comment https://forums.phpfreaks.com/topic/108727-preg_replace-characters-in-a-phone-number/#findComment-557574 Share on other sites More sharing options...
nikefido Posted June 4, 2008 Author Share Posted June 4, 2008 $fixed = preg_replace('/[\. \- \s]/', '/', $phone); Link to comment https://forums.phpfreaks.com/topic/108727-preg_replace-characters-in-a-phone-number/#findComment-557598 Share on other sites More sharing options...
effigy Posted June 4, 2008 Share Posted June 4, 2008 /\D+/ would be more encompassing. Link to comment https://forums.phpfreaks.com/topic/108727-preg_replace-characters-in-a-phone-number/#findComment-557602 Share on other sites More sharing options...
nikefido Posted June 4, 2008 Author Share Posted June 4, 2008 /\D+/ would be more encompassing. wouldn't that replace...everything? not just the things between the numbers? or is \D any non-numeric? Link to comment https://forums.phpfreaks.com/topic/108727-preg_replace-characters-in-a-phone-number/#findComment-557606 Share on other sites More sharing options...
effigy Posted June 4, 2008 Share Posted June 4, 2008 \D = non-digit. Link to comment https://forums.phpfreaks.com/topic/108727-preg_replace-characters-in-a-phone-number/#findComment-557608 Share on other sites More sharing options...
nikefido Posted June 4, 2008 Author Share Posted June 4, 2008 tyvm, change made Link to comment https://forums.phpfreaks.com/topic/108727-preg_replace-characters-in-a-phone-number/#findComment-557609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.