Home  >  Article  >  Backend Development  >  How to convert lowercase to uppercase in php string

How to convert lowercase to uppercase in php string

青灯夜游
青灯夜游Original
2021-09-23 11:42:272843browse

How to convert php string from lowercase to uppercase: 1. Use strtoupper() function, syntax "strtoupper($string)"; 2. Use mb_strtoupper() function, syntax "mb_strtoupper($string,$encoding) )".

How to convert lowercase to uppercase in php string

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

php string will Convert lowercase to uppercase

Method 1: Use strtoupper() function

strtoupper() function can convert letters in a string to uppercase , the syntax format is as follows:

strtoupper($string)

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

The sample code is as follows:

<?php
$str = "https://www.php.cn/";
$str = strtoupper($str);
echo $str;
?>

The running results are as follows:

HTTPS://WWW.PHP.CN/

Method 2: Use the mb_strtoupper() function

mb_strtoupper( ) The function of the function is similar to the strtoupper() function. It can also convert letters in the string to uppercase, and the mb_strtoupper() function can also set the character encoding of the parameter. Its syntax is as follows:

mb_strtoupper($string [, $encoding = mb_internal_encoding()])

Among them, $string is the string that needs to be converted, and $encoding is an optional parameter used to set the character encoding of the parameter.

The difference from the strtoupper() function is that the letters in $string are determined through the Unicode character attribute. Therefore, the mb_strtoupper() function is not affected by the locale setting and can convert any character with a "letter" attribute, such as a umlaut (ä).

The sample code is as follows:

<?php
header("Content-type:text/html;charset=utf-8");
$str = "https://www.php.cn/";
$str = mb_strtoupper($str);
echo $str . &#39;<br>&#39;;
$str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
$str = mb_strtoupper($str, &#39;UTF-8&#39;);
echo $str;
?>

The running results are as follows:

How to convert lowercase to uppercase in php string

##Recommended learning:

php training

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