Skip to content

Instantly share code, notes, and snippets.

@baras
Created September 5, 2018 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baras/edb18f55925348ce2a2bb808695d6cf5 to your computer and use it in GitHub Desktop.
Save baras/edb18f55925348ce2a2bb808695d6cf5 to your computer and use it in GitHub Desktop.
/**
* 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