Define the first letter of the $ variable in capital [duplicate]

0

I'm using MYSQL to show some data on my site ... But some data is in lowercase, and I need the first letter to be in Capital.

But I do not know how to do this using variable ... I need the data of my variable "$name" to be with the first letter in capital letters.

    
asked by anonymous 26.04.2018 / 00:21

2 answers

3

You can use the ucfirst method, which converts the first letter to uppercase:

<?php
$name= "texto";
$name = ucfirst($name);
echo $name; // retorna 'Texto'
?>
    
26.04.2018 / 00:30
1

If you want to make all the words in the sentence with the first letter capitalized, you can also use ucwords:

echo ucwords("olá mundo!");
//Sairá: Olá Mundo!
    
26.04.2018 / 01:34