Created
September 5, 2018 06:34
-
-
Save baras/edb18f55925348ce2a2bb808695d6cf5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Convert human readable strings to machine names. | |
* | |
* @param string $str | |
* The string to convert. | |
* | |
* @return string | |
* The converted string. | |
*/ | |
function machine_readable( $str ) { | |
// $str must be a string. | |
if ( ! is_string( $str ) ) { | |
return ''; | |
} | |
return preg_replace( '@[^a-z0-9_]+@', '_', strtolower( trim( $str ) ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment