Magento: Get sentence case from camel case string

· kalpesh

Magento has pre-defined methods for getters and setters which will convert camelcase string to underscore formatted string.
Example, Magento will convert thisIsDummy to this_is_dummy using it’s method _underscore which is available at Varien_Object class.

If you want to convert Camel case string to Sentence case (this may sound weird, but we got the requirement),
Example, from thisIsDummy to This Is Dummy, below method will help you to do so:

public function camelToSentence($word) {  
 if(isset($word)) {  
 $result = ucwords(preg_replace(‘/(.)([A-Z])/’, “$1 $2”, $word));  
 return $result;  
 }  
 }

#camel case to sentence case #camelize to underscore #magento getter setter