When I run the following code, I’m receiving this output:
PHP
PHP What
PHP What is
PHP What is PHP
However I want to receive the following output:
PHP What is PHP
PHP What is
PHP What
PHP
What thing needs to change to extract values from Upper to Lower
<?php
// Horje.Com
$stringSentence = 'PHP What is PHP';
$stringSentence = preg_replace('/s+/', ' ', $stringSentence);
$buffer = '';
$count = 1;
$length = strlen($stringSentence);
for ($i = 0; $i < $length; $i++) {
if ($stringSentence[$i] !== ' ') {
$buffer .= $stringSentence[$i];
} else {
//echo ' '.$count++.' '.$buffer.'</br>';
$pieces = explode(" ", $stringSentence);
$first_part = implode(" ", array_splice($pieces, 0, $count++));
echo ''.$first_part.'</br>';
$buffer = '';
}
}
$pieces = explode(" ", $stringSentence);
$first_part = implode(" ", array_splice($pieces, 0, $count++));
echo ''.$first_part.'';