Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add white space between word

Tags:

php

I want to add space to word something like this

CountryName
RegionName
ZipPostalCode

to be

Country Name
Region Name
Zip Postal Code

Let me know how can be done with php

like image 448
wow Avatar asked Jan 15 '11 17:01

wow


2 Answers

You can use regular expressions to find [lowercase character][uppercase character] and insert a space:

$newstr = preg_replace('/([a-z])([A-Z])/s','$1 $2', $oldstr);
like image 168
Mark Elliot Avatar answered Nov 15 '22 13:11

Mark Elliot


You might look into CakePHP's Inflector class for guidance (for example the humanize function).

like image 37
JRL Avatar answered Nov 15 '22 13:11

JRL