Home > Blockchain >  How to add a space between words?
How to add a space between words?

Time:12-26

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';?>

CodePudding user response:

You could use preg_replace with a regex option:

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