watsmyname Posted March 1, 2010 Share Posted March 1, 2010 Hello, Well i have var $string var, which might hold a string like this "$23.59 per pack", "$23.59/boxes","23.59 per vial" and so on and in any form. All i need to do is truncate all characters and leave only numeric value, i.e 23.59 only. All i could think is using array of those unwanted words and replace them with a blank space. is there any way to do this task easily? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/193757-truncating-alphabets-and-other-characters-from-string/ Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 $new_string = ereg_replace("[^.0-9]", "", $string); Link to comment https://forums.phpfreaks.com/topic/193757-truncating-alphabets-and-other-characters-from-string/#findComment-1019811 Share on other sites More sharing options...
jl5501 Posted March 1, 2010 Share Posted March 1, 2010 or $new_string = preg_replace ('/[^\d\s.]/', '', $string); Link to comment https://forums.phpfreaks.com/topic/193757-truncating-alphabets-and-other-characters-from-string/#findComment-1019823 Share on other sites More sharing options...
watsmyname Posted March 1, 2010 Author Share Posted March 1, 2010 Thanks a ton guys Link to comment https://forums.phpfreaks.com/topic/193757-truncating-alphabets-and-other-characters-from-string/#findComment-1019982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.