Apr 18, 2012
kalpesh

Magento: Get sentence case from camel case string

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:

1
2
3
4
5
6
public function camelToSentence($word) {
            if(isset($word)) {
                $result = ucwords(preg_replace('/(.)([A-Z])/', "$1 $2", $word));
                return $result;
            }
        }

1 Comment

  • Thank You for sharing the information it is very benefited .

    keep sharing more post.

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions