Set the first letter of the $variable in uppercase

Asked

Viewed 533 times

0

I am using MYSQL to show some data on my website... But some data is in lower case, and I need the first letter to be uppercase.

However I do not know how to do this using variable... I need the data of my variable "$name" uppercase the first letter.

  • Useful links http://php.net/manual/en/function.ucfirst.php http://php.net/manual/en/function.strtolower.php http://php.net/manual/en/function.strtoupper.php

2 answers

3

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

<?php
$name= "texto";
$name = ucfirst($name);
echo $name; // retorna 'Texto'
?>

1

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

echo ucwords("olá mundo!");
//Sairá: Olá Mundo!
  • ucwords tb is legal. + 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.