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

How to convert words to uppercase letters in php

青灯夜游
Release: 2023-03-15 13:36:01
Original
2090 people have browsed it

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)
Copy after login

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);;
?>
Copy after login

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)
Copy after login

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);;
?>
Copy after login

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!

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