0

This function caps a specific letter of a string, and returns the updated string.
THe first letter is 0, as it is default as well.

<?php
function cap_letter($string,$letter=0) {
  $letters = str_split($string);
  $letters[$letter] = strtoupper($letters[$letter]);
  return implode($letters);
}
?>
3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by Shaffer
0

I think you mean capitalize. If you capitolize it you turn it into money. I wasn't aware PHP was the philosopher's stone of the 21st century

0

Since a string is defined as an array of characters, you can actually just have line #4 without converting the string to and from an array. In other words:

$word = 'happy';
echo $word[0];

would return 'h'.

0

Hello,
Thanks for the feedback.
As for cscgal's comment, I want to say that I wanted to leave it with the least amount of code.

Thanks,
Shaffer.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.