What is the function in php to convert the first letter from lower case to upper case?

青灯夜游
Release: 2023-03-15 09:00:01
Original
3562 people have browsed it

Function to convert the first letter from lowercase to uppercase in php: 1. ucfirst() function, which can convert the first letter of a string to uppercase, the syntax is "ucfirst($str)"; 2. ucwords() function, You can convert the first letter of each word in a string to uppercase with the syntax "ucwords($str)".

What is the function in php to convert the first letter from lower case to upper case?

The operating environment of this tutorial: Windows 7 system, PHP version 7.1, DELL G3 computer

The functions to convert the first letter from lower case to upper case in php are Two types:

  • ucfirst() function, which can convert the first letter of the string into uppercase

  • ucwords() function, which can convert the characters Convert the first letter of each word in the string to uppercase

1. ucfirst() function

ucfirst() function converts the first letter of each word in the string to uppercase The first character is converted to uppercase.

Example:

<?php
echo ucfirst("hello world!");
?>
Copy after login

What is the function in php to convert the first letter from lower case to upper case?

2. ucwords() function

ucwords() function The first character of each word in the string is converted to uppercase.

Grammar:

ucwords($string [, $delimiters = "\t\r\n\f\v" ])
Copy after login

Among them, $string is the string that needs to be converted; $delimiters is an optional parameter, used to represent word delimiters. The default is space and tab. character, line feed character, carriage return character, horizontal line and vertical bar.

Example:

<?php
$foo = &#39;hello world!&#39;;
$foo = ucwords($foo);             // Hello World!
echo $foo."<br>";

$foo = &#39;hello|world!&#39;;
$bar = ucwords($foo);             // Hello|world!
echo $bar."<br>";

$baz = ucwords($foo,"|");        // Hello|World!
echo $baz."<br>";
?>
Copy after login

Output:

Hello World!
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 from lower case to upper case?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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