Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add a space between words?

I have a string that has words without any spaces between them. How do I add a space between each word? Example: my string has combined words FinancialTimes and I would like it to show as Financial Times

<?php $word = 'FinancialTimes';?>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could use preg_replace with a regex option:

$word = "FinancialTimes";
$output = preg_replace("/(?<=[a-z])(?=[A-Z])/", " ", $word);
echo $output;  // Financial Times
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading