PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

strtoupper> <strtok
Last updated: Fri, 04 Jul 2008

view this page in

strtolower

(PHP 4, PHP 5)

strtolower — Pasa a minúsculas una cadena

Descripción

string strtolower ( string $cadena )

Devuelve la cadena con todas sus letras en minúsculas.

Nótese que las letras son definidas por la localización actual (el "locale" actual). Esto quiere decir que, por ejemplo, en el locale por defecto ("C"), los caracteres como la Ñ no serán convertidos.

Example #1 Ejemplo de strtolower()

<?php
$cadena 
"El vEloZ mUrciÉlAgo Hindú ComÍA feliZ CardillO y KiWi";
$cadena strtolower($cad);        
echo 
$cadena# Salida: el veloz murciélago hindú comía feliz cardillo y kiwi
?>

Note: Esta función es segura binariamente.

Vea también strtoupper(), ucfirst(), ucwords() y mb_strtolower().



strtoupper> <strtok
Last updated: Fri, 04 Jul 2008
 
add a note add a note User Contributed Notes
strtolower
Piotr
10-Mar-2008 02:24
///charset=iso-8859-2
 function strtolower_iso8592($string)
    {
        $low=array("ˇ" => "±", "Ć" => "ć", "Ę" => "ę", "Ł" => "ł", "Ó" => "ó", "¦" => "¶", "Ż" => "ż", "¬" => "Ľ", "Ń" => "ń");
        return strtolower(strtr($string,$low));
       
       
       
    }
toringe at infostill dot com
25-Oct-2007 03:27
This will work for all languages using ISO8859_1 - more code than many other but fast.

<?php
function strtolower_iso8859_1($s){
   
$i = strlen($s);
    while (
$i > 0) {
        --
$i;
       
$c =ord($s[$i]);
        if ((
$c & 0xC0) == 0xC0) {
           
// two most significante bits on
           
if (($c != 215) and ($c != 223)){ // two chars OK as is
                // to get lowercase set 3. most significante bit if needed:
               
$s[$i] = chr($c | 0x20);
            }
        }
    }
    return
strtolower($s);
}   
?>
patricia at steuerungb dot de
17-Oct-2007 06:29
When you're not sure, how the current locale is set, you might find the following function useful. It's strtolower for utf8-formatted text:

<?php
function strtolower_utf8($inputString) {
   
$outputString    = utf8_decode($inputString);
   
$outputString    = strtolower($outputString);
   
$outputString    = utf8_encode($outputString);
    return
$outputString;
}
?>

It's not suitable for every occasion, but it surely gets in handy. I use it for lowering German 'Umlauts' like ä and ö.
mr dot blober at gmail dot com
16-Jun-2007 11:39
simple example for Polish characters
<?php
function strtolower_pl($str)
{
return
strtr(strtolower($str), '[ĄĆĘŁŃÓŚŹŻ]', '[ąćęłńóśźż]');
}
?>
rok dot kralj at gmail dot com
04-Jun-2007 11:49
Slovenian characters

<?php
   
function strtolower_slovenian($string)
    {
       
$low=array("Č" => "č", "Ž" => "ž", "Š" => "š");
        return
strtolower(strtr($string,$low));
    }

?>
marco at recchiuti dot it
22-May-2007 12:43
Maybe it is not so elegant, but it Works.
It's just a fast Idea and it is what I need.
Any hacks for other characters (link !, ? etc etc) should help.

function RemoveShouting($string)
{
     $frase = "";   
     $astri = explode(".", $string);
     foreach ($astri as $elem)
    $frase .= " ".ucfirst(trim(strtolower($elem))).". ";
      
    return trim($frase);
}

Cheers!
M
mario dot kostelac at gmail dot com
29-Apr-2007 04:42
This is strtolower function for Croatian characters:
function strToLowerCro($string){
    $string = strtolower($string);
    $patterns[0] = '/Č/';
    $patterns[1] = '/Ć/';
    $patterns[2] = '/Ž/';
    $patterns[3] = '/Š/';
    $patterns[4] = '/Đ/';
    $replacements[0] = 'č';
    $replacements[1] = 'ć';
    $replacements[2] = 'ž';
    $replacements[3] = 'š';
    $replacements[4] = 'đ';
    $string = preg_replace($patterns, $replacements, $string);
    return $string;
}
Enjoy...
HQ063
31-Mar-2007 01:37
Similar to last function, but for spanish
    function strtolower_es($string)
    {
        $low=array("Á" => "á", "É" => "é", "Í" => "í", "Ó" => "ó", "Ú" => "ú", "Ü" => "ü", "Ñ" => "ñ");
        return strtolower(strtr($string,$low));
    }
Dinçer Akay
20-Dec-2006 02:32
Turkish Character
<?php
   
function strtolower_tr($string)
    {
       
$low=array("Ü" => "ü", "Ö" => "ö", "Ğ" => "ğ", "Ş" => "ş", "Ç" => "ç", "İ" => "i", "I" => "ı");
        return
strtolower(strtr($string,$low));
    }

?>
Enzo_01 at abv dot bg
06-Nov-2006 11:31
two functions what works with cyrilic text

function cyr_strtolower($a) {
        $offset=32;
        $m=array();
        for($i=192;$i<224;$i++)$m[chr($i)]=chr($i+$offset);
        return strtr($a,$m);
}
function cyr_strtoupper($a) {
        $offset=32;
        $m=array();
        for($i=192;$i<224;$i++)$m[chr($i+$offset)]=chr($i);
        return strtr($a,$m);
}

ex:
 cyr_strtoupper("абвгде"); // АБВГДЕ
 cyr_strtolower("АБВГДЕ"); // абвгде
eduardor2k at redr2k dot com
08-Aug-2006 02:34
I changed it a bit and i found that it's better to put everything in lowercase, and rebuild the text the same way a teacher corrects a text, for now it only checks that the first letter after a point "." must be
in upper case.

    function RemoveShouting($string)
    {
        $string = strtolower(trim($string));
      
        for($i=0;$i<strlen($string);$i++){
      
            if($i==0){$string[$i] = strtoupper($string[$i]);}
          
            if($string[$i] == "."){
                while($string[$i+1] == " "){
                    $i++;
                }
                $string[$i+1] = strtoupper($string[$i+1]);
                $i++;
            }
        }
      
    return $string;
    }

this function would change:
Hi mi name is PETER. SOME TIMES I FORGOT TO DISABLE CAPS LOCK.

into:

Hi mi name is peter. Some times i forgot to disable caps lock.
spiceee ddotty spiceee com
06-Mar-2006 04:53
If you ever need to strtolower a string with href tags on it and doesn't want to mess with the characters inside a tag, this is for you.

<?php

function loweroutsidetags ($str) {
   
$chars = preg_split ("//", $str);
   
$tolower = true;
   
$str = '';

    foreach (
$chars as $k) {
        if (
$k == '<') { $tolower = false; }
        if (
$tolower) { $k = strtolower ($k); }
       
$str .= $k;   
        if (
$k == '>') { $tolower = true; }
    }
    return
$str;
}

?>

this:
echo loweroutsidetags('aALalala <a href="?q=CASEsENSITIVINESSinURLSareSTUPID">')

will give:
aalalala <a href="?q=CASEsENSITIVINESSinURLSareSTUPID">
red at iklanumum dot com
23-Feb-2006 06:43
I've seen this as a common use from script developers, so I would like to share the alternative way to compare 2 string (CASE INSENSITIVE) without using strtolower for faster process.

Use strcasecmp() for comparison purpose rather than comparing uncertain case of 2 string variables, because strcasecmp() is approximately 60% faster, moreover, the greater its string length the greater the difference,!
Ex. case :
$var1;    -> could be a mixture of upper & lower case
$var2;    -> could be a mixture of upper & lower case

To compare whether $var1 is exactly the same as $var2 (case insensitive manner):
Use -> if (strcasecmp($var1,$var2)==0)
rather than -> if (strtolower($var1)==strtolower($var2))
Patrick
19-Jan-2006 10:57
If you're considering using the below unhtmlentities function from phpContrib, I would suggest this one as an alternative:

<?php
function unhtmlentities($string)
{
  
// replace numeric entities
  
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
  
$string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
  
// replace literal entities
  
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
  
$trans_tbl = array_flip($trans_tbl);
   return
strtr($string, $trans_tbl);
}
?>

That was copied exactly from the html_entity_decode manual page.  It'll handle numeric entities correctly, the below function won't.
fackelkind
11-Jan-2006 12:03
Nifty? :D

<?php
       
function is_lowercase ($str){
                return (
$str == strtolower ($str));
        }
?>
mhuggins57 at yahoo dot com
19-Jul-2005 04:04
There's a ucfirst "function" to make the first character uppercase, but there's no "lcfirst" function to make the first character lowercase.  Here's my own code to accomplish this.

<?
function lcfirst($str) {
    return strtolower(substr($str, 0, 1)) . substr($str, 1);
}
?>

I found this particularly useful for generating XML nodes with the Reflection class.
kmcdermott at perimeterinstitute dot ca
08-Dec-2004 01:04
To do case insensitive comparisons in a database, strtolower() can be a quick and dirty solution:

$Sql = "SELECT * FROM tablename WHERE LOWER(column_name) = '".strtolower($my_var)."'";
phpContrib (A T) esurfers d o t c o m
24-Sep-2004 11:07
<?php

$b
=html_entity_decode(strtolower(htmlentities($a)));

?>

will convert to lowercase most accented vocals
(it will convert into &Agrave; into &agrave; into )

This is not fast and clean code, it is just a quick oneliner to help you if you need a quick way to do it



Users with older versions of PHP can use:
$b=unhtmlentities(strtolower(htmlentities($a)));

// with unhtmlentities() as defined in the html_entity_decode() manual page:

function unhtmlentities ($string) {
    $trans_tbl =get_html_translation_table (HTML_ENTITIES );
    $trans_tbl =array_flip ($trans_tbl );
    return strtr ($string ,$trans_tbl );
}
bkimble at ebaseweb dot com
19-Jan-2003 10:39
Heres a small function I wrote to stop people from submitting data that is ALL IN CAPS SO THEY CAN GET MORE ATTENTION THAT THE REST OF THE USER SUBMITTED DATA on my website :) If you can make it better, by all means do so. This function splits up words delimited by a space, and makes only the first letter of each word capitalized. You can easily modify it so it's only the very first word of the string. I've also added some exceptions so you don't make things like roman numerals look like "Iii" or "Xcmii" or something.

function RemoveShouting($string)
{
 $lower_exceptions = array(
        "to" => "1", "a" => "1", "the" => "1", "of" => "1"
 );
 
 $higher_exceptions = array( 
        "I" => "1", "II" => "1", "III" => "1", "IV" => "1", 
        "V" => "1", "VI" => "1", "VII" => "1", "VIII" => "1",
        "XI" => "1", "X" => "1"
 );
 
 $words = split(" ", $string);
 $newwords = array();
 foreach ($words as $word)
 {
  if (!$higher_exceptions[$word]) $word = strtolower($word);
  if (!$lower_exceptions[$word]) $word[0] = strtoupper($word[0]);
  array_push($newwords, $word);
 }
 return join(" ", $newwords);
}

BK
tty01_at_rambler_dot_ru
19-Sep-2002 07:58
Another solution for Double-Byte-Characters, based on iconv() functions, not sensible to the current locale, works on win32.

/* Converts charset */
function myConvertCharset($str, $from, $to)
{
    if(@function_exists('iconv'))
    {
        return iconv($from, $to, $str);
    }
    else if(@function_exists('recode_string'))
    {
        return recode_string($from . '..'  . $to, $str);
    }
    else
    {
        print "function iconv not exists";
        return $str;
    }
}
/* Converts a string to lowercase */
function my_strtolower($s)
{
    $t = "windows-1251";
    $d = "UTF-8";
    return myConvertCharset(strtolower(myConvertCharset($s, $d, $t)), $t, $d);
}

print my_strtolower("СЛОВО  Uppercase");
12-Sep-2002 05:17
This function is sensible to the current locale, namely the LC_CTYPE category (the default LC_CTYPE category is set from the LANG environment variable or by an explicit LC_CTYPE setting, but it can be overriden by the LC_ALL environment setting). If no locale setting is done in the enironment, the default locale will be C, for which the lowercase/uppercase conversion is based on the default character set of the system: this may convert only ASCII letters, or also ISO-8859-1 letters depending on the system...

strtoupper> <strtok
Last updated: Fri, 04 Jul 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites