Created
March 23, 2014 08:33
-
-
Save jmillerdesign/9720353 to your computer and use it in GitHub Desktop.
Convert any string to an integer between 0-9
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 | |
/** | |
* Convert any string to an integer between 0-9 | |
* | |
* @param string $str Any string | |
* @return integer Integer between 0-9 | |
*/ | |
function strToInt($str) { | |
preg_match('/\d/', md5((string) $str), $matches, PREG_OFFSET_CAPTURE); | |
return ($matches[0]) ? (integer) $matches[0][0] : 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment