Home  >  Article  >  Backend Development  >  Introduction to the usage of PHP case conversion functions (strtolower, strtoupper)

Introduction to the usage of PHP case conversion functions (strtolower, strtoupper)

WBOY
WBOYOriginal
2016-07-25 08:58:241382browse
This article introduces the usage of the case conversion functions strtolower and strtoupper in PHP, which are often encountered in character processing problems. Friends in need, please refer to it.

1, Convert string to lowercase strtolower function: This function converts all characters of the incoming string parameter to lowercase and puts them back into the string in decimal form. Example:

<?php
    $str = "I want To FLY";
    $str = strtolower($str);
    echo $str;
//by bbs.it-home.org
?>

Output: i want to fly

2, convert characters to uppercase strtoupper function: The function of this function is opposite to the strtolower function. It converts all the characters of the incoming character parameter into uppercase and returns the string in uppercase. The usage is the same as strtolower().

Here are two more useful functions.

3. Convert the first character of the string to uppercase ucfirst function: The function of this function is to change the first character of the string to uppercase. This function returns the string with the first character uppercase. The usage is similar to the strtolower() function.

4, convert the first character of each word in the string to uppercase ucwords: This function capitalizes the first character of each word in the passed string. For example, "hello world", after processing by this function, "Hello Word" will be returned. Usage is similar to strtolower().



Statement:
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