Home >Backend Development >PHP Problem >How to convert English to lowercase in php

How to convert English to lowercase in php

藏色散人
藏色散人Original
2021-09-15 10:54:372256browse

How to convert English to lowercase in php: 1. Use the lcfirst() function to change the first letter of the first English word to lowercase; 2. Use the strtolower() function to change all letters to lowercase.

How to convert English to lowercase in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to convert English to lowercase in php?

Change the first letter of the first word to lowercase: lcfirst()

The code is as follows:

<?php
$foo = &#39;HelloWorld&#39;;
$foo = lcfirst($foo);             // helloWorld
$bar = &#39;HELLO WORLD!&#39;;
$bar = lcfirst($bar);             // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
?>

Change all letters to lowercase: strtolower()

The strtolower() function converts a string to lowercase, and the syntax is "strtolower(string)".

Note: This function is binary safe.

Related introduction:

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

The code is as follows:

<?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!
?>

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

The code is as follows:

<?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!
?>

Change all letters to uppercase: strtoupper()

Recommended study: "PHP Video Tutorial

The above is the detailed content of How to convert English to lowercase in php. 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