How to explode a word at capital letters(camelCase)?

Example string: "myExampleWord" should output "My Example Word"

Asked 25 Aug, 17 at 12:45 AM

Rishu Singh
Php String

Answer

Try this:

<?php 
$char = "myExampleWord";
$pieces = preg_split('/(?=[A-Z])/',$char);
echo " String " . ucfirst(implode(" ", $pieces));
?>

like