Home > Backend Development > PHP Problem > What are the functions that convert php to lowercase?

What are the functions that convert php to lowercase?

青灯夜游
Release: 2023-03-15 20:42:01
Original
1693 people have browsed it

Function to convert to lowercase: 1. strtolower(), syntax "strtolower($str)"; 2. mb_strtolower(), syntax "mb_strtolower($str,"coding")"; 3. lcfirst() , syntax "lcfirst($str)".

What are the functions that convert php to lowercase?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php transfer lowercase function

Function name Function
strtolower Convert the string to lowercase
lcfirst Convert the first letter of the string to lowercase
mb_strtolower Convert the string Convert to lowercase (difference from strtolower function)

Let’s introduce them separately below.

1) strtolower

strtolower() function can convert the letters in the string to lowercase. The syntax format is as follows:

strtolower($str)
Copy after login

Among them, $string is a parameter of string type. This function can convert the letters in the parameter $string to lowercase and return the converted string.

The sample code is as follows:

<?php
header("Content-type:text/html;charset=utf-8");
$str = "HTTPS://WWW.PHP.CN/";
echo "原字符串:".$str."<br>";
$str = strtolower($str);
echo "转小写后:".$str;
?>
Copy after login

The running results are as follows:

What are the functions that convert php to lowercase?

##2) mb_strtolower## The function of #mb_strtolower() function is similar to that of strtolower() function. It can also convert the letters in the string to lowercase, and the mb_strtolower() function can also set the character encoding of the parameter. The syntax format is as follows:

mb_strtolower($str [, $encoding = mb_internal_encoding()])
Copy after login

Among them, $str is the string that needs to be converted, and $encoding is an optional parameter used to set the character encoding of the parameter.

The difference from the strtolower() function is that the detection of alphabetic characters in $str is based on the Unicode attribute of the character. The behavior of the function is therefore independent of the language setting and can convert any character with a "letter" attribute, such as the umlaut A (Ä).

The sample code is as follows:

<?php
header("Content-type:text/html;charset=utf-8");
$str = "HTTPS://WWW.PHP.CN/";
$str = strtolower($str);
echo $str.&#39;<br>&#39;;
$str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
$str = mb_strtolower($str, &#39;UTF-8&#39;);
echo $str;
?>
Copy after login

The running result is as follows:

What are the functions that convert php to lowercase?##3) lcfirst

## The #lcfirst() function can convert the first character of a string to lowercase. The syntax format is as follows:

lcfirst($str)
Copy after login
Among them, $str is the string that needs to be converted.

The sample code is as follows:

<?php
    $str = &#39;Hello World!&#39;;
    $str = lcfirst($str);
    echo $str.&#39;<br>&#39;;
    $str2 = &#39;HELLO WORLD!&#39;;
    $str2 = lcfirst($str2);
    echo $str2;
?>
Copy after login

The running results are as follows:

##Recommended learning: "

PHP Video Tutorial

" What are the functions that convert php to lowercase?

The above is the detailed content of What are the functions that convert php to lowercase?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template