Silverado_NL Posted March 21, 2007 Share Posted March 21, 2007 hi everybody, im currently trying to automate the process of cleaning up Telephone Fields. currently there are loads of fields in the database that contain both alphabetical characters and integer characters. is there a command to remove these alphabetical characters in the string???? my goal is to end up with only number and no other characters. if anybody has a clue, i'd sure like to know:) Thanks you in advance. Silverado Link to comment https://forums.phpfreaks.com/topic/43657-removing-alphabetical-characters-from-string/ Share on other sites More sharing options...
Iceman512 Posted March 21, 2007 Share Posted March 21, 2007 Hey Silverado, Try this: <?php $string = "This is the string that needs to have letters stripped from it, leaving: 1, 2, 3, 4, 5, ..."; $new_string = ereg_replace("[^A-Za-z]", "", $string ); ?> Hope it works, Iceman Link to comment https://forums.phpfreaks.com/topic/43657-removing-alphabetical-characters-from-string/#findComment-211930 Share on other sites More sharing options...
Orio Posted March 21, 2007 Share Posted March 21, 2007 my goal is to end up with only number and no other characters. In that case you need to make a little change with Iceman's script: <?php $string = "123This is the string that needs to have letters stripped from it, leaving: 1, 2, 3, 4, 5, ..."; $new_string = ereg_replace("[^0-9]", "", $string ); //$new_string now holds 12312345 ?> Orio. Link to comment https://forums.phpfreaks.com/topic/43657-removing-alphabetical-characters-from-string/#findComment-211942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.