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

How to case strings in PHP

青灯夜游
青灯夜游Original
2019-02-13 18:13:502066browse

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)

Example:

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

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)

Example:

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

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)

Example:

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

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)

Example:

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

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!

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