strtolower
TRANSFORMS all alphabetic characters of a given
STRING into lowercase.
Some characters, especially those accented, may not be properly converted.
This function, as expected, has no effect on non-alphabetic characters.
Note that accented characters are not properly converted to lowercase.
This means that texts in languages other than English may have conversion difficulties; as long as they have uppercase and lowercase characters.
Using the mb_strtolower function solves the problem.
This will be seen at the specific time, in another chapter of this tutorial.
<?php
str strtolower ( str $str )
where,
$str = STRING to be converted to lowercase
?>
$str
The STRING to be converted to lowercase.
EXERCISE
<?php
$st01 = "TIME IS MONEY. (LET'S UP-TO-DATE?)";
echo 'Original STRING:<br>' . $st01 .
'<br><br>lowercase:<br>' . strtolower($st01);
?>
RESULT
Original STRING:
TIME IS MONEY. (LET'S UP-TO-DATE?)
lowercase:
time is money. (let's up-to-date?)
EXERCISE
<?php
$st02 = "LOVE'S NOT TIME'S FOOL, THOUGH ROSY LIPS
AND CHEEKS WITHIN HIS BENDING SICKLE'S COMPASS COME;
OR BENDS WITH THE REMOVER TO REMOVE. LET ME NOT TO
THE MARRIAGE OF TRUE MINDS IF THIS BE ERROR AND
UPON ME PROVED, OH, NO, IT IS AN EVER FIXED MARK.
WHICH ALTERS WHEN IT ALTERATION FINDS,
IT IS THE STAR TO EVERY WAND'RING BARK,
ADMIT IMPEDIMENTS; LOVE IS NOT LOVE.";
echo 'Original STRING:<br>' . $st02 .
'<br><br>lowercase:<br>' . strtolower($st02);
?>
RESULT
Original STRING:
LOVE'S NOT TIME'S FOOL, THOUGH ROSY LIPS AND CHEEKS WITHIN HIS BENDING SICKLE'S COMPASS COME; OR BENDS WITH THE REMOVER TO REMOVE. LET ME NOT TO THE MARRIAGE OF TRUE MINDS IF THIS BE ERROR AND UPON ME PROVED, OH, NO, IT IS AN EVER FIXED MARK. WHICH ALTERS WHEN IT ALTERATION FINDS, IT IS THE STAR TO EVERY WAND'RING BARK, ADMIT IMPEDIMENTS; LOVE IS NOT LOVE.
lowercase:
love's not time's fool, though rosy lips and cheeks within his bending sickle's compass come; or bends with the remover to remove. let me not to the marriage of true minds if this be error and upon me proved, oh, no, it is an ever fixed mark. which alters when it alteration finds, it is the star to every wand'ring bark, admit impediments; love is not love.
EXERCISE
<?php
$st03 = "* ARQUÉTIPO DO AMOR ROMÂNTICO, ROMEU E JULIETA
RETRATADOS POR FRANK DICKSEE AMOR (DO LATIM AMORE)
É UMA EMOÇÃO OU SENTIMENTO QUE LEVA UMA PESSOA A
DESEJAR O BEM A OUTRA PESSOA OU A UMA COISA.
O USO DO VOCÁBULO, CONTUDO, LHE EMPRESTA OUTROS
TANTOS SIGNIFICADOS, QUER COMUNS, QUER CONFORME
A ÓPTICA DE APRECIAÇÃO, TAL COMO NAS RELIGIÕES,
NA FILOSOFIA E NAS CIÊNCIAS HUMANAS. ";
echo 'Original STRING:<br>' . $st03 .
'<br><br>lowercase:<br>' . strtolower($st03);
?>
RESULT
Original STRING:
* ARQUÉTIPO DO AMOR ROMÂNTICO, ROMEU E JULIETA RETRATADOS POR FRANK DICKSEE AMOR (DO LATIM AMORE) É UMA EMOÇÃO OU SENTIMENTO QUE LEVA UMA PESSOA A DESEJAR O BEM A OUTRA PESSOA OU A UMA COISA. O USO DO VOCÁBULO, CONTUDO, LHE EMPRESTA OUTROS TANTOS SIGNIFICADOS, QUER COMUNS, QUER CONFORME A ÓTICA DE APRECIAÇÃO, TAL COMO NAS RELIGIÕES, NA FILOSOFIA E NAS CIÊNCIAS HUMANAS.
lowercase:
* arquÉtipo do amor romÂntico, romeu e julieta retratados por frank dicksee amor (do latim amore) É uma emoÇÃo ou sentimento que leva uma pessoa a desejar o bem a outra pessoa ou a uma coisa. o uso do vocÁbulo, contudo, lhe empresta outros tantos significados, quer comuns, quer conforme a Óptica de apreciaÇÃo, tal como nas religiÕes, na filosofia e nas ciÊncias humanas.
Note that accented characters are not properly converted to lowercase.
This means that texts in languages other than English may have conversion difficulties.
Using the mb_strtolower function this situation will be solved, which will be seen soon in the special chapter of this tutorial..
EXERCISE
<?php
$st04 = "* ארכיטיפיה של אהבה רומנטית, רומאו ויולי
פורטרט מאת פרנק דיקסי אמור (מלטימאר אמור)
זוהי הרגשה או תחושה שלוקחים אדם
רוצה טוב אחר לאדם אחר או לדבר אחד.
השימוש במושג, עם זאת, הוא אוהב אתכם אחרים
כל כך הרבה משמעות, רוצה נפוץ, רוצה כמו
אופטי הערכה, כמו דתיים,
בפילוסופיה ומדעי האדם.";
echo 'Original STRING:<br>' . $st04 .
'<br><br>lowercase:<br>' . strtolower($st04);
?>
EXERCISE
<?php
if( substr(PHP_OS, 0, 3) == 'WIN') {
if (!setlocale(LC_ALL, 'C')) {
die('skip need "C" locale (this windows is broken)');
}
} else {
if (!setlocale(LC_ALL, 'en_US.UTF-8', 'en')) {
die('skip need "en_US.UTF-8" locale');
}
}
if( substr(PHP_OS, 0, 3) == 'WIN') {
setlocale(LC_ALL, 'C');
} else {
setlocale(LC_ALL, 'en_US.UTF-8');
}
echo "Testing strtolower() with 128 chars:<br>";
for ($i=0; $i<=127; $i++){
$char = chr($i);
print(bin2hex($char))." => ".(bin2hex(strtolower("$char")))."<br>";
}
echo "<br><br>Testing strlower() with basic strings:<br>";
$str = "Mary Had A liTTle LAmb and ShE loveD IT So\n";
var_dump(strtolower($str));
echo "<br><br>Testing strtolower() with various strings:<br>";
/* strings to pass strtolower() */
$strings = array (
"",
"string",
"stRINg0234",
"1.233.344StrinG12333",
"$$$$$$!!!!@@@@@@@ ABCDEF !!!***",
"ABCD\0abcdABCD",
NULL,
TRUE,
FALSE,
);
$count = 0;
/* loop through to check possible variations */
foreach ($strings as $string) {
echo "<br><br>Iteration: $count<br>";
var_dump( strtolower($string) );
$count++;
}
echo "<br><br>Testing strtolower() with two
different case strings:<br>";
if (strtolower("HeLLo woRLd") === strtolower("hEllo WORLD"))
echo "strings are same, with Case Insensitive\n";
else
echo "strings are not same\n";
?>
EXERCISE
<?php
if (substr(PHP_OS, 0, 3) != "WIN" ||
!setlocale(LC_CTYPE, "English_United States.1252"))
die('skip Run only on Windows
with locale "English_United States.1252" available');
setlocale(LC_CTYPE, "English_United States.1252");
echo "Testing strtolower() with all 256 chars:<br>";
for ($i=0; $i<=255; $i++){
$char = chr($i);
print(bin2hex($char))." => ".(bin2hex(strtolower("$char")))."<br>";
}
echo "<br><br>Testing strlower() with basic strings:<br>";
$str = "Mary Had A liTTle LAmb and ShE loveD IT So\n";
var_dump(strtolower($str));
echo "<br><br>Testing strtolower() with various strings:<br>";
/* strings to pass strtolower() */
$strings = array (
"",
"string",
"stRINg0234",
"1.233.344StrinG12333",
"$$$$$$!!!!@@@@@@@ ABCDEF !!!***",
"ABCD\0abcdABCD",
NULL,
TRUE,
FALSE,
);
$count = 0;
/* loop through to check possible variations */
foreach ($strings as $string) {
echo "<br><br>Iteration: $count<br>";
var_dump( strtolower($string) );
$count++;
}
echo "<br><br>Testing strtolower() with
two different case strings:<br>";
if (strtolower("HeLLo woRLd") === strtolower("hEllo WORLD"))
echo "strings are same, with Case Insensitive\n";
else
echo "strings are not same\n";
?>