Home > Backend Development > PHP Tutorial > How to case strings in PHP

How to case strings in PHP

青灯夜游
Release: 2023-04-05 08:00:02
Original
2093 people have browsed it

In PHP, you can use: strtoupper() function, strtolower() function, ucfirst() function, lcfirst() function to case strings. The following article will give you a detailed introduction, I hope it will be helpful to you.

How to case strings in PHP

strtoupper() function

strtoupper() function can take a string as a parameter, and then The string is converted to all uppercase and returned.

Basic syntax:

strtoupper(string)
Copy after login

Example:

<?php 
function toUpper($string){ 
    return(strtoupper($string)); 
} 
$string="Hello world!";   
echo (toUpper($string)); 
?>
Copy after login

Output:

How to case strings in PHP

##strtolower( )Function

strtolower() function can take a string as a parameter, then convert all strings to lowercase and return.

Basic syntax:

strtolower(string)
Copy after login

Example:

<?php 
function toUpper($string){ 
    return(strtolower($string)); 
} 
$string="JAVASCRIPT";   
echo (toUpper($string)); 
?>
Copy after login

Output:

How to case strings in PHP

##ucfirst( )Function ucfirst() function can take a string as a parameter, and then convert the first letter of the string to uppercase, leaving other characters unchanged, and return.

Basic syntax:

ucfirst(string)
Copy after login

Example:

<?php 
function toUpper($string){ 
    return(ucfirst($string)); 
} 
$string="hello world!";   
echo (toUpper($string)); 
?>
Copy after login

Output:

How to case strings in PHP

##lcfirst( ) Function

lcfirst() function can take a string as a parameter, and then convert the first letter of the string to lowercase, leaving the other characters unchanged, and return it.

Basic syntax:

lcfirst(string)
Copy after login

Example:

<?php 
function toUpper($string){ 
    return(lcfirst($string)); 
} 
$string="PHP中文网!";   
echo (toUpper($string)); 
?>
Copy after login
Output:

The above is the entire content of this article , I hope it can be helpful to everyone’s study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! ! How to case strings in PHP

The above is the detailed content of How to case strings in PHP. For more information, please follow other related articles on the PHP Chinese website!

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