Skip to content
Advertisement

Add spaces between words in a camelCased string then uppercase the first word

I have two types of strings, hello and helloThere.

What I want is to change them so they read like: Hello and Hello There depending on the case.

What would be a good way of doing this?

Advertisement

Answer

you can use ucwords like everyone said… to add the space in helloThere you can do $with_space = preg_replace('/[A-Z]/'," $0",$string); then ucwords($with_space);

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement