Home  >  Article  >  Backend Development  >  PHP conversion case tutorial basics

PHP conversion case tutorial basics

小云云
小云云Original
2017-11-28 09:24:591535browse

In order to take care of friends who are just learning PHP, this chapter will share with you the most basic knowledge: how to convert upper and lower case in PHP. We will use examples to explain.

strtoupper()

All letters become uppercase

strtolower()

All letters become lowercase

ucwords()

The first letter of each word is converted to uppercase

ucfirst()

The first letter of the first word is converted to uppercase

lcfirst()

The first letter of the first word becomes lowercase

Example:

$foo = 'hello world!';
$foo = ucwords($foo);             // Hello World!
 
$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
 
$foo = 'hello world!';
$foo = ucfirst($foo);             // Hello world!
 
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
 
$foo = 'HelloWorld';
$foo = lcfirst($foo);             // helloWorld
 
$bar = 'HELLO WORLD!';
$bar = lcfirst($bar);             // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!

The above content is a detailed explanation of PHP case conversion. I hope this website will be helpful to everyone.

Related recommendations:

How to convert upper and lower case in python

Example of converting the first letter of a string to upper and lower case in php_PHP tutorial

php string first letter conversion to uppercase and lowercase

The above is the detailed content of PHP conversion case tutorial basics. 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