Automattic\WooCommerce\Blueprint

Util::camel_to_snakepublic staticWC 1.0

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() code WC 9.9.5

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 );
}