PHP: Replace space in front of capitals in a string (Regex)

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 - My Home Is Here

$String = 'TheCambodia';
$Words = preg_replace('/(?<!\ )[A-Z]/', ' $0', $String);
echo $Words;


Output: The Cambodia

Comments

Popular posts from this blog

PHP: Date Difference for PHP 5.2

HTML5 video loop src change on end play function

display the_content with setup_postdata