Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to replace all Uppercase letters with spacing?

Tags:

regex

php

$string = "MaryGoesToSchool";

$expectedoutput = "Mary Goes To School";
like image 988
ggggggggg Avatar asked Jan 10 '10 10:01

ggggggggg


1 Answers

Try:

$string = 'MaryGoesToSchool';
$nStr = preg_replace_callback('/[A-Z]/', function($matches){
    return $matches[0] = ' ' . ucfirst($matches[0]);
}, $string);
echo trim($nStr);
like image 167
bananaCute Avatar answered Oct 07 '22 06:10

bananaCute