Home >Backend Development >PHP Problem >How to convert words to uppercase letters in php

How to convert words to uppercase letters in php

青灯夜游
青灯夜游Original
2022-02-23 19:38:522096browse

Conversion method: 1. Use the strtoupper() function to convert all letters of the words in the string to uppercase, the syntax is "strtoupper(string)"; 2. Use the ucwords() function to convert the characters to uppercase The first letter of each word in the string is converted to uppercase, using the syntax "ucwords(string)".

How to convert words to uppercase letters in php

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

php will string Convert Chinese words into uppercase letters

1. Use strtoupper() function

strtoupper() function can convert the letters in the string into Uppercase, the syntax format is as follows:

strtoupper($string)

Among them, $string is a string type parameter. This function can convert the letters in the parameter $string to uppercase and return the converted string. .

Example:

<?php
$str = "Hello World";
echo strtoupper($str);;
?>

How to convert words to uppercase letters in php

2. Use the ucwords() function

ucwords() function to convert the string The first character of each word in the parameter $string is converted to uppercase. The syntax format is as follows:

ucwords($string)

Among them, $string is a parameter of string type. This function can convert the first character of each word in the parameter $string to Uppercase and return the converted string.

Example:

<?php
$str = "Hello World";
echo ucwords($str);;
?>

How to convert words to uppercase letters in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert words to uppercase letters 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