How to define a PHP string, what should you pay attention to when defining it? As a member of "Xiaobai", let us discuss it together! ! ! Let's Go!!!
There are three ways to declare strings in PHP language:
Declared with single quotes
Declared with double quotes
Declared with character delimiters
1: For single quote declaration
Use English half-width single quotes and put the string inside;
The code is as follows:
<?php //声明字符串变量$zifu $zifu = '欢迎来到PHP中文网'; echo $zifu; ?>
The result is as follows:
2: Double quotation mark declaration string
Add double quotes on both sides of the string
For example, the code is as follows:
<?php //声明字符串变量$zifu $zifu = "欢迎来到PHP中文网"; echo $zifu; ?>
The result is as follows:
Combined with the above examples, what is the connection or difference between single quotation marks and double quotation marks?
1: Double quotes parse variables, but single quotes do not parse variables;
Additional explanation code is as follows:
<?php //声明字符串变量$zifu $zifu='欢迎'; $zifu = '$zifu来到PHP中文网'; echo $zifu; ?>
The results are as follows:
2: Insert the variable in double quotes, after the variable If there are Chinese, English or Chinese characters, then double quotes will treat them as a whole variable, so special characters must be used to separate them in the end;
3: If you don’t want to have spaces when inserting double quotes into variables , we can wrap variables with curly braces.
4: For escape characters, double quotes parse escape characters, single quotes do not.
5: For the use of single and double quotation marks, use single quotation marks as much as possible, because the efficiency of single quotation marks is higher than that of double quotation marks;
Recommendation: "PHP Video Tutorial》
The above is the detailed content of What is a string in PHP data type and why should we define a string (source code attached). For more information, please follow other related articles on the PHP Chinese website!