-
-
Save Narven/8cd1c31074bd13fdcb6f to your computer and use it in GitHub Desktop.
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
<?php | |
$str = '13++56-461.79/27--14-abc'; | |
$filter = filter_var($str,FILTER_SANITIZE_NUMBER_INT); | |
$onlyDigitsFilterVar = str_replace(array('+', '-'), '', $filter); | |
$onlyDigitsRegexp1 = preg_replace('/[^\d]/', '', $str); | |
$onlyDigitsRegexp2 = preg_replace('/[^[:digit:]]/', '', $str); // http://www.php.net/manual/en/regexp.reference.character-classes.php | |
var_dump($filter); // string(19) "13++56-4617927--14-" | |
var_dump($onlyDigitsFilterVar); // string(13) "1356461792714" | |
var_dump($onlyDigitsRegexp1); // string(13) "1356461792714" | |
var_dump($onlyDigitsRegexp2); // string(13) "1356461792714" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment