kingb00zer Posted October 28, 2012 Share Posted October 28, 2012 Hi I am attempting to strip the letters from certain input boxes within my website and seem to have a hard time understanding how preg_replace works. Here is the code I have; $x= $_POST['inputdata'];$y= preg_replace("[^0-9]", "", $x); The letters wont strip from the input box and I cant work out why. Link to comment Share on other sites More sharing options...
niche Posted October 28, 2012 Share Posted October 28, 2012 (edited) Always check the manual http://us3.php.net/m...reg-replace.php I've also found this site to be helpful http://www.regular-expressions.info/charclass.html Edited October 28, 2012 by niche Link to comment Share on other sites More sharing options...
Ingolme Posted October 28, 2012 Share Posted October 28, 2012 The regular expression is missing delimiters.Try this:$y= preg_replace("/[^0-9]/", "", $x); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now