-1

I'm trying to remove the '-' from a string and capitalize the word before the '-'. For example:

fraser-ultra-2019 becomes FraserUltra2019

Right now I can only remove the '-' with str_replace but not sure how to capitalize it.

$string = fraser-ultra-2019
str_replace("-","",$string) // fraserultra2019
stalwart1014
  • 451
  • 1
  • 9
  • 29

1 Answers1

1

How about something like:

str_replace(' ', '', ucwords(str_replace('-', ' ', $string)));

The ucwords() function will capitalise all words in a given string so long as they are split by a space.

Be sure to wrap your $string value in single or double quotes before writing this to a PHP file.

matigo
  • 1,321
  • 1
  • 6
  • 16