Home > Backend Development > PHP Problem > 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?

青灯夜游
Release: 2023-03-13 12:56:01
Original
2453 people have browsed it

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)
Copy after login

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;
?>
Copy after login

Output result:

Hello world!
Hello world!
Copy after login

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!

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