Skip to content

Instantly share code, notes, and snippets.

@jmillerdesign
Created March 23, 2014 08:33
Show Gist options
  • Save jmillerdesign/9720353 to your computer and use it in GitHub Desktop.
Save jmillerdesign/9720353 to your computer and use it in GitHub Desktop.
Convert any string to an integer between 0-9
<?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