php - Can regex do this faster? -
I have to capitalize each word and add it to 1 word, such as:
Home = Home - About Us = About Us
Can I use this function at this time, can it be better or more efficient?
public function formatClassName ($ name) {$ name = str_replace ('-', '', $ name); $ Name = ucwords ($ name); $ Name = str_replace ('', '', $ name); Return $ name; } I do not think a regex can capitalize the word, so you want There are still two different regexes, and I think with such simple cases, regular expression overkill (seems hunting squirrel with Artillery) This code is simple, clear and easy to understand. Do not touch IT!
Comments
Post a Comment