Automattic\WooCommerce\Blueprint
Util::camel_to_snake
Convert a string from camelCase to snake_case.
Method of the class: Util{}
No Hooks.
Returns
String.
Usage
$result = Util::camel_to_snake( $input );
- $input(string) (required)
- The string to be converted.
Util::camel_to_snake() Util::camel to snake code WC 10.8.1
public static function camel_to_snake( $input ) {
// Replace all uppercase letters with an underscore followed by the lowercase version of the letter.
$pattern = '/([a-z])([A-Z])/';
$replacement = '$1_$2';
$snake = preg_replace( $pattern, $replacement, $input );
// Replace spaces with underscores.
$snake = str_replace( ' ', '_', $snake );
// Convert the entire string to lowercase.
return strtolower( $snake );
}