Created
November 14, 2012 15:59
-
-
Save ArupSen/4072951 to your computer and use it in GitHub Desktop.
extract numbers from string regexp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To remove anything that is not a number: | |
$output = preg_replace('/[^0-9]/', '', $input); | |
/* | |
Explanation: | |
[0-9] matches any number between 0 and 9 inclusively. | |
^ negates a [] pattern. | |
So, [^0-9] matches anything that is not a number, and since we're using preg_replace, they will be replaced by nothing '' (second argument of preg_replace). | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment