8

I have a word default and I want a php function to make only first letter capital. Can we do that. Please help me out as I am very new to php coding.

Shahnewaz
  • 360
  • 4
  • 12
  • 3
    http://php.net/results.php?q=first%2520letter%2520of%2520word%2520capital&l=en&p=wholesite – deceze Apr 04 '11 at 08:57
  • First search result on Google: https://encrypted.google.com/search?q=How+to+make+first+letter+of+a+word+capital+php – Gordon Apr 04 '11 at 09:05
  • 1
    Thanks I will keep the track of this site! –  Apr 04 '11 at 09:05
  • You should try some searching on the web, because if you would searched for it on the Google you would have been got a correct answer in first place. Just keep this in mind first search and if not get the correct answer then ask. – Jack Billy Apr 04 '11 at 09:06
  • 1
    Thanks Jack Billy, I think from next time I will do that. –  Apr 04 '11 at 09:07

5 Answers5

17

You may want to use ucfirst().

For multibyte strings, please see this snippet.

Community
  • 1
  • 1
fabrik
  • 14,094
  • 8
  • 55
  • 71
  • 1
    Thanks fabrik! This worked in first place and I think I will not be a beginner for any longer! Thanks again! –  Apr 04 '11 at 09:00
6

ucfirst capitalizes the first letter in a string.

ucwords capitalizes every word in a string.

Philip
  • 4,128
  • 5
  • 31
  • 49
2

Hello Geeta you can simply use ucwords() php function to make every first letter of your word Upper Cased!

Hope this would help!

Jack Billy
  • 7,141
  • 6
  • 27
  • 38
2

I think that http://se2.php.net/manual/en/function.ucwords.php is the best function here :)

Etu
  • 41
  • 3
2

This is the code you need:

<?php

$string = 'stackoverflow';
$string = ucfirst($string);
echo $string;

?>
Erre Efe
  • 15,387
  • 10
  • 45
  • 77