Php put a space in front of capitals in a string (Regex)

前端 未结 4 1150
天涯浪人
天涯浪人 2020-12-03 02:47

I have a number of strings which contain words which are bunched together and I need to seperate them up.

For example ThisWasCool - This Was Cool
MyHomeIsHere -

4条回答
  •  感动是毒
    2020-12-03 03:02

    $string = preg_replace('/[A-Z]/', ' $0', $string);
    

    Maybe run the result through ltrim after.

    $string = ltrim(preg_replace('/[A-Z]/', ' $0', $string));
    

提交回复
热议问题