/    Sign up×
Community /Pin to ProfileBookmark

Is there a better way to do this?

I dont see myself using this elsewhere in the application so I don’t want to make it a stand alone function. I feel like there is probably a preg_replace that would do what I want more efficiently.

[code=php]
//This makes $col = “overviewContentEditable”;
$col = str_replace(” “,””,lcfirst(ucwords(str_replace(“_”,” “,”overview_content_editable”))));[/code]

It does exactly what I need it too, just wondering if there was a faster way.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 23.2014 — Maybe (untested):
[code=php]
$result = preg_replace_callback(
'/_+([^_])/',
function($matches) {
return strtoupper($matches[1]);
},
$inputString
);
[/code]

As to whether that's actually more efficient processing-wise, you'd have to do some metering to find out. (Regex functions in general tend to be less efficient than comparable built-in string functions, but in a more complex case like this, the only way to tell would be to try it and measure it.
×

Success!

Help @NoEffinWay spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...