From 1c7eb0d59acc023769326b8a2f751e5aedaf91fe Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Sep 2014 22:34:58 +0200 Subject: [PATCH] lib: Introduce function `String::cname()' --- library/Icinga/Util/String.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/library/Icinga/Util/String.php b/library/Icinga/Util/String.php index b64d9e524..0bebb06e7 100644 --- a/library/Icinga/Util/String.php +++ b/library/Icinga/Util/String.php @@ -21,4 +21,18 @@ class String { return array_map('trim', explode($delimiter, $value)); } + + /** + * Uppercase the first character of each word in a string assuming and removing the underscore as word separator + * + * Converts 'first_name' to 'firstName' for example. + * + * @param string $name + * + * @return string + */ + public static function cname($name) + { + return str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($name)))); + } }