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 Quote Link to comment 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]. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.