patternphpMajor
Converting snake_case to PascalCase
Viewed 0 times
convertingsnake_casepascalcase
Problem
Is there an effective way, maybe with regex, to change the following text pattern?
I have a string like
I have a string like
abc_def_ghi_jkl. I want to replace it to AbcDefGhiJkl. I currently use the following code to change it. Is there a more effective way than this?implode('',array_map('ucfirst',explode('_',$string)));Solution
More effective solution:
From Gears library
str_replace('_', '', ucwords($key, '_'));From Gears library
Code Snippets
str_replace('_', '', ucwords($key, '_'));Context
StackExchange Code Review Q#48593, answer score: 26
Revisions (0)
No revisions yet.