Use the "ucfirst($foo);" method to convert the first word The first letter becomes capitalized."/> Use the "ucfirst($foo);" method to convert the first word The first letter becomes capitalized.">

Home >Backend Development >PHP Problem >How to convert the first letter of php to uppercase

How to convert the first letter of php to uppercase

藏色散人
藏色散人Original
2021-09-01 10:32:182133browse

How to convert the first letter of php to uppercase: 1. Create a PHP sample file; 2. Use the "ucwords($foo)" method to convert the first letter of each word to uppercase; 3. Use "ucfirst ($foo);" method capitalizes the first letter of the first word.

How to convert the first letter of php to uppercase

The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer

How to convert the first letter of php to uppercase?

php method to convert the first letter from lowercase to uppercase

Convert the first letter of each word to uppercase: ucwords()

<?php
$foo = &#39;hello world!&#39;;
$foo = ucwords($foo);             // Hello World!
 
$bar = &#39;HELLO WORLD!&#39;;
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>

ucwords () function converts the first character of each word in a string to uppercase.

Change the first letter of the first word to uppercase: ucfirst()

<?php
$foo = &#39;hello world!&#39;;
$foo = ucfirst($foo);             // Hello world!
 
$bar = &#39;HELLO WORLD!&#39;;
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>

ucfirst() function converts the first character in the string to uppercase.

Recommended: "PHP Video Tutorial"

The above is the detailed content of How to convert the first letter of php to uppercase. 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