I’m trying to use preg_replace to remove all characters from a string except for numeric and period characters.
I can remove everything but numbers, however how can I make an exception for the ‘.’ period character.
Can anyone help me out?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try this:
But you could also use
[^0-9.]if you’re more familiar with that. Note that the.doesn’t need to be escaped inside the character class declaration as it’s not a special character inside there (only],\and depending on the context also^and-).