ballhogjoni Posted March 12, 2008 Share Posted March 12, 2008 Hi all, I want my code to replace all characters accept for 0-9 and the period. This is my code so far, I just don't know where to place the period so that preg replce knows to keep it. // say the user submitted this to post amount: 43%$3&*(.98 $string = preg_replace("/[^0-9s]/", "", $_POST['amount']); // I want my script to echo 433.98 Thanks in advance Link to comment https://forums.phpfreaks.com/topic/95831-preg-replace-question/ Share on other sites More sharing options...
effigy Posted March 12, 2008 Share Posted March 12, 2008 Simply add it to the character class. Why do you have an "s" in there? /[^\d.]/ \d is shorthand for [0-9]. Link to comment https://forums.phpfreaks.com/topic/95831-preg-replace-question/#findComment-490585 Share on other sites More sharing options...
ballhogjoni Posted March 12, 2008 Author Share Posted March 12, 2008 I have an s in there cuz i don't know what i am doing thx. Link to comment https://forums.phpfreaks.com/topic/95831-preg-replace-question/#findComment-490591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.