Can regex do this faster?

php, regex

Solution

I don't think a regex can capitalize the words, so you'd still have to have two separate regexes, and I think with such simple cases, regular expressions are overkill (think hunting squirrels with artillery). This code is simple, clear and easy to understand. DON'T TOUCH IT!

Problem

I want to capitalise each word and combine it into 1 word, e.g: home = Home about-us = AboutUs Here is the function I use at the moment, can regex do this better or more efficient? ``` public function formatClassName($name) { $name = str_replace('-', ' ', $name); $name = ucwords($name); $name = str_replace(' ', '', $name); return $name; } ```

Original source