In the development of PHP, we often need to set the configuration of capitalization. Here, we'll share how to set up case sensitivity to give you more control over how your program runs.
First of all, we need to make it clear: the names of variables, functions, classes, etc. in PHP are case-sensitive. This means that if we define a variable $myVar, then both $myvar and $MyVar are different variables. Similarly, if we define a function myFunction, then Myfunction and myfunction are different functions.
So, how to set the upper and lower case in PHP? The following are some common methods and techniques:
Modify the PHP configuration file
In the PHP configuration file php.ini, there is a configuration item called "sensitivity", which controls Is PHP case sensitive? By default, this option is turned on (the value is "On"), which means that PHP is case sensitive. If we want to turn off this option, we can change it to "Off". The specific operation method is to find the following code in php.ini:
; Case sensitive ; Default Value: On ; Development Value: On ; Production Value: On sensitivity = On
Change the sensitivity value to Off, and then restart PHP.
Using functions
PHP provides some functions to control case, such as strtolower() and strtoupper(). These two functions convert strings to lowercase and uppercase respectively, regardless of the built-in case sensitivity settings. For example:
echo strtolower("HELLO WORLD"); // 输出hello world
Using operators
PHP provides three operators for comparison, they are "==", "===" and "!=" . The "==" and "!=" operators ignore case, while the "===" operator is strictly case-sensitive. For example:
$myVar = "Hello"; if ($myVar == "hello") // 忽略大小写,此条件成立 if ($myVar === "hello") // 严格区分大小写,此条件不成立
In short, in PHP development, we need to pay attention to the setting and control of upper and lower case to avoid unnecessary errors and affect the normal operation of the program. The above introduces some common methods and techniques for PHP developers to refer to and use.
The above is the detailed content of How to set upper and lower case in PHP. For more information, please follow other related articles on the PHP Chinese website!