How to add a space before chamel case charecter using PHP

Suppose you have a string with chamel case and now you want to add a space or something else before every chamel case charecter then you are on the right place. Here i am going to explain how can you do this by using minimal code and effort. 

So be here and read the complete article. Lets understand this by example.

Suppose you have some chamel case strings like below -

-- phpSollutions
--- faceBook
---- linkedIn
----- extraMark
------ partTimeJob

<?php

$string = "phpSollutions";

$pattern = '/([a-z])([A-Z])/s';

$replace = '${1} ${2}';

$output = preg_replace($pattern, $replace, $string);

echo $output;

?>


Output: Now the output will be looking like this-

-- php Sollutions
--- face Book
---- linked In
----- extra Mark
------ part Time Job


Please don't forgot to leave a comment if you like this post. 


Chears :)
Happy Coding..

Post a Comment

Previous Post Next Post