-- Sep 21 In-Class Exercise Thread
<?php
$sentence = "it is wednesday my dudes";
function reverseStringAndCapitalizeFirstLetter($sentence) {
// split the string based on empty space delimiter
$splitSentence = explode(" ", $sentence);
// reverse through array, capitalize first letter of each word and print
// it out
for ($i = count($splitSentence)-1; $i >= 0; $i--) {
$string = $splitSentence[$i];
$newWord = substr($string, 0, 1);
$newWord = strtoupper($newWord);
$newWord = $newWord . substr($string, 1, strlen($string)) . " ";
echo $newWord;
}
}
reverseStringAndCapitalizeFirstLetter($sentence);
?>
<?php
$sentence = "it is wednesday my dudes";
function reverseStringAndCapitalizeFirstLetter($sentence) {
// split the string based on empty space delimiter
$splitSentence = explode(" ", $sentence);
// reverse through array, capitalize first letter of each word and print
// it out
for ($i = count($splitSentence)-1; $i >= 0; $i--) {
$string = $splitSentence[$i];
$newWord = substr($string, 0, 1);
$newWord = strtoupper($newWord);
$newWord = $newWord . substr($string, 1, strlen($string)) . " ";
echo $newWord;
}
}
reverseStringAndCapitalizeFirstLetter($sentence);
?>