当前位置:网站首页>Use of string type "PHP Basics"
Use of string type "PHP Basics"
2022-07-27 08:07:00 【Go home at night】
Functional requirements
Apply single quotation marks and double quotation marks to output the same variable , The output results are completely different , The double quotation marks output the value of the variable , The output of single quotation marks is a string .
The sample code
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Use of single and double quotation marks </title>
</head>
<body>
<?php
echo '\'\\<br />'; // Output :'\
$a = 10;
echo 'The a value is $a <br />';
echo "The a value is $a <br />";
?>
</body>Running results
Knowledge description
A string is a sequence of consecutive characters , By digital 、 A combination of letters and symbols . Each character in the string takes only one byte . stay PHP in , Defining strings mainly uses single quotation marks (') And double quotes (") Two ways .
(1) Single quotation marks can be used to define strings “'” Cover up , If you want to represent single quotes in a string , Escape character is required “\” The single quotation mark can only be output after being converted . If a backslash appears before a single quotation mark or at the end of the string “\”, Use two backslashes to indicate .
Single quotation marks define the format :
$a = ' character string ';
(2) Use double quotes “"” Enclosing a string can also define a string . If you want to represent double quotation marks in the defined string , You also need to use escape characters to transfer .
Double quotation marks define the format :
$a = " character string ";
The difference between the two is , Variables contained in double quotes are automatically replaced with actual values , The variables contained in single quotation marks are output as ordinary strings .
When using escape characters , Use single quotes , Just use single quotation marks “'” Escape , But use double quotation marks “"” when , Also note the double quotation marks “"”、“$” The use of characters such as . These special characters must pass through the transfer character “\” To display . Commonly used escape characters .
\n and \r stay Windows There is no difference in the system , Can be used as a carriage return . But in Linux There are two effects in the system , stay Linux in \n Change to the next line , But will not return to the beginning of the line ; and \r Indicates that the cursor returns to the beginning of the line , But still in the bank .
Be careful : If you use “\”, So when outputting ,“\” It will also be output together .
explain : When defining a simple string , Using single quotation marks is a more appropriate treatment . If you use double quotes ,PHP It will take some time to deal with the escape of strings and the parsing of variables . therefore , When defining a string , If there are no special requirements , Try to use single quotation marks .
边栏推荐
猜你喜欢

【Day42 文献精读】A Bayesian Model of Perceived Head-Centered Velocity during Smooth Pursuit Eye Movement

Teach you to build a nail warning robot hand in hand

杂谈:把肉都烂在锅里就是保障学生权益了?

Comprehensive cases

C#winform 窗体事件和委托结合用法

The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?

Enhancement: BTE process introduction
![[target detection] yolov6 theoretical interpretation + practical test visdrone data set](/img/ad/78835eea4decc15e0981e6561b875f.png)
[target detection] yolov6 theoretical interpretation + practical test visdrone data set

Gossip: it's really important to have a rod in your hand and a net on your shoulder. As for how many fish are in the basket?

Five day travels to Beijing
随机推荐
想让照片中的云飘起来?视频编辑服务一键动效3步就能实现
I can't figure out why MySQL uses b+ trees for indexing?
mqtt指令收发请求订阅
opengauss从库停掉,发现主库无法写入数据
Demo:st05 find text ID information
[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL
C commissioned use cases
物来顺应,未来不迎,当时不杂,既过不恋
"Intermediate and advanced test questions": what is the implementation principle of mvcc?
C#winform 窗体事件和委托结合用法
Promise详解
Abstract factory pattern
Database startup report error_ user_ connect_ times &gt; 0 error
Happy holidays, everyone
企业架构驱动的数字化转型!
Primary key in MySQL secondary index - MySQL has a large number of same data paging query optimization
The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?
Shenzhi Kalan Temple
Things come to conform, the future is not welcome, at that time is not miscellaneous, neither love
杂谈:把肉都烂在锅里就是保障学生权益了?