Changement de casse en PHP
Le changement de casse consiste à transformer une chaîne minuscule en majuscule ou inversement. La conversion minuscule en majuscule se fait en PHP avec la fonction strtoupper() et l’inverse avec la fonction strtolower().
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
$chaineMinuscule = "daniel";
echo strtoupper($chaineMinuscule)."<br>";
$chaineMajuscule = "DAVID";
echo strtolower($chaineMajuscule);
?>
<?php
$chaineMinuscule = "daniel";
echo strtoupper($chaineMinuscule)."<br>";
$chaineMajuscule = "DAVID";
echo strtolower($chaineMajuscule);
?>
<?php
$chaineMinuscule = "daniel";
echo strtoupper($chaineMinuscule)."<br>";
$chaineMajuscule = "DAVID";
echo strtolower($chaineMajuscule);
?>
Affichage
DANIEL
david
Pour mettre le premier caractère de la chaîne en majuscule, utilisez la fonction ucfirst().
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
$chaine = "daniel a sommeil";
echo ucfirst($chaine);
?>
<?php
$chaine = "daniel a sommeil";
echo ucfirst($chaine);
?>
<?php
$chaine = "daniel a sommeil";
echo ucfirst($chaine);
?>
Affichage
Daniel a sommeil
Pour mettre en majuscule la première lettre de chaque mot d’une chaîne, utilisez la fonction ucwords().
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
$chaine = "daniel a sommeil";
echo ucwords($chaine);
?>
<?php
$chaine = "daniel a sommeil";
echo ucwords($chaine);
?>
<?php
$chaine = "daniel a sommeil";
echo ucwords($chaine);
?>
Affichage
Daniel A Sommeil