How to convert the first letter of php to uppercase

藏色散人
Release: 2023-03-12 09:18:02
Original
2023 people have browsed it

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

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!