search for in the  
<strtokstrtoupper>
Last updated: Thu, 19 May 2005

strtolower

(PHP 3, PHP 4, PHP 5)

strtolower -- Make a string lowercase

Description

string strtolower ( string str )

Returns string with all alphabetic characters converted to lowercase.

Note that 'alphabetic' is determined by the current locale. This means that in i.e. the default "C" locale, characters such as umlaut-A (أ„) will not be converted.

Example 1. strtolower() example

<?php
$str
= "Mary Had A Little Lamb and She LOVED It So";
$str = strtolower($str);
echo
$str; // Prints mary had a little lamb and she loved it so
?>

Note: This function is binary-safe.

See also strtoupper(), ucfirst(), ucwords() and mb_strtolower().



User Contributed Notes
strtolower
kmcdermott at perimeterinstitute dot ca
08-Dec-2004 03: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 01: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 );
}
jostor at gmail dot com
20-Sep-2004 01:30
strtolower() does not change the swedish and german special chararchters. This simple script does that as well:

<?php
/*
string swe_strtolower( string string )
*/
function swe_strtolower($str) {
 
$ar = array('ه' => 'إ', 'ن' => 'ؤ', 'ِ' => 'ض', 'ü' => 'ـ');
 
$str = strtolower($str);
 foreach (
$ar as $key) {
 
$str = str_replace($key, $ar, $str);
 }
}

/*
string swe_strtoupper( string string )
*/
function swe_strtoupper($str) {
 
$ar = array('ه' => 'إ', 'ن' => 'ؤ', 'ِ' => 'ض', 'ü' => 'ـ');
 
$str = strtoupper($str);
 foreach (
$ar as $key) {
 
$str = str_replace($ar, $key, $str);
 }
}
?>
unordained at pseudotheos dot com
18-Jun-2004 08:33
[adding to zaid's] For databases where LIKE queries are not case-insensitive (firebird, for example), do

$field_value = strtoupper($field_value);

WHERE ... UPPER($field_name) LIKE '%$field_value%' ...

it won't use an index (unless you omit the first %), but you don't have to use lots of OR statements together, and still risk missing something.
visualmind at php dot net
14-Apr-2003 03:52
Regarding the note above from info at saudiabm dot com:

Using strtolower or strtoupper to convert non-ascii charachters like Arabic and etc requires setlocale LC_CTYPE first http://www.php.net/setlocale

echo strtolower('هذه العبارة ستظهر بشكل غير صحيح'); // this will look messy
setlocale(LC_CTYPE, 'ar_SA'); // Using arabic Saudi char set
echo strtolower('هذه العبارة شتظهر بشكل صحيح'); // this will look fine

on windows you can use setlocale(LC_CTYPE, 'arabic');
bkimble at ebaseweb dot com
20-Jan-2003 12: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 09: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 07: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...
OMatla at gmx dot net
11-Sep-2002 10:02
In addition to the post by zaid@designerz.com:

There is no need to do all those upper-/lowercase conversions prior to a mysql query, since LIKE is case-insensitive unless you define the operand to be BINARY.

Editor's Note: ...unless the field was declared BINARY in the CREATE TABLE statement :)
--zak@php.net
zaid at designerz dot com
09-Aug-2002 04:47
//compare user input with database.  Insert the call to the function inside your sql statement
//by zaid@designerz.com
function compare($field_name, $string)
{
  $string_lower = strtolower($string);  //makes $string all lower case
  $string_upper = strtoupper($string);  //makes $string all upper case
  $string_ucfirst = ucfirst($string_lower); //capitalizes first letter
  $string_ucwords = ucwords($string_lower); //converts a whole phrase to first upper
  return " ($field_name Like '" . $string . "%' Or $field_name Like '" . $string_upper . "%' Or $field_name Like '" . $string_ucfirst . "%' Or $field_name Like '" . $string_ucwords . "%') " ;
}

<strtokstrtoupper>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT