Home  >  Article  >  Backend Development  >  What is the function in php to convert the first letter to capital?

What is the function in php to convert the first letter to capital?

青灯夜游
青灯夜游Original
2021-10-20 18:57:032370browse

In PHP, the function that converts the first letter to uppercase is ucfirst(). The function of this function is to convert the first letter of a string to uppercase. The syntax is "ucfirst(string)".

What is the function in php to convert the first letter to capital?

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

In php, I want to convert To capitalize the first letter, you can use the ucfirst() function. (On the contrary, if you want to convert the first letter to lowercase, you can use the lcfirst() function.)

ucfirst function can convert the first letter of a string to uppercase. The syntax format is as follows:

ucfirst($string)

Among them, $string is the string that needs to be converted.

Example:

<?php
    $str = &#39;hello world!&#39;;
    $str = ucfirst($str);
    echo $str.&#39;<br>&#39;;
    $str2 = &#39;HELLO WORLD!&#39;;
    $str2 = ucfirst(strtolower($str2));
    echo $str2;
?>

Output result:

Hello world!
Hello world!

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the function in php to convert the first letter to capital?. For more information, please follow other related articles on the PHP Chinese website!

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