How to convert lowercase to uppercase in php string

青灯夜游
Release: 2023-03-12 20:56:02
Original
2863 people have browsed it

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

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 = "//m.sbmmt.com/";
$str = strtoupper($str);
echo $str;
?>
Copy after login

The running results are as follows:

HTTPS://WWW.PHP.CN/
Copy after login

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

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 = "//m.sbmmt.com/";
$str = mb_strtoupper($str);
echo $str . &#39;<br>&#39;;
$str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
$str = mb_strtoupper($str, &#39;UTF-8&#39;);
echo $str;
?>
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!