当前位置:网站首页>What is the concept of string in PHP
What is the concept of string in PHP
2022-06-30 02:46:00 【Yisu cloud】
stay php What is the concept of string in
This article introduces “ stay php What is the concept of string in ” Knowledge about , During the operation of the actual case , Many people will encounter such difficulties , Next, let Xiaobian lead you to learn how to deal with these situations ! I hope you will read carefully , Be able to learn !
stay php in , A string is a continuous sequence of characters , Consists of a series of characters , Each character is equivalent to a byte . There are three ways to define a string :1、 Wrap the characters in single quotation marks , grammar “' String content '”;2、 Wrap the characters in double quotation marks , grammar “" String content "”;3、 Use heredoc syntactic structure “<<<”, grammar “<<<EOF Character content EOF;”.

The operating environment of this tutorial :windows7 System 、PHP8.1 edition 、DELL G3 The computer
php String in
A string is a continuous sequence of characters , Consists of a series of characters , Each character is equivalent to a byte .
In other languages , Characters and strings are two different data types , But in PHP in , Treat characters and strings as string data types .
stay PHP in , There are three ways to define a string , These are the single quotation marks 、 Double quotation marks 、Heredoc The way .
Use single quotation marks to define the string
The easiest way to define a string is to enclose it in single quotes ( character ').
To express a single quotation mark itself , It needs to be preceded by a backslash (\) To escape . To express a backslash itself , Use two backslashes (\\). Any other backslash will be treated as the backslash itself : That is, if you want to use other escape sequences, such as \r perhaps \n, Does not mean anything special , Just the two characters themselves .
<?phpecho 'this is a simple string';echo '<br>';// You can enter multiple lines echo 'You can also have embedded newlines instrings this way as it isokay to do';echo '<br>';// Output : Arnold once said: "I'll be back"echo 'Arnold once said: "I\'ll be back"';echo '<br>';// Output : You deleted C:\*.*?echo 'You deleted C:\\*.*?';echo '<br>';// Output : You deleted C:\*.*?echo 'You deleted C:\*.*?';echo '<br>';// Output : This will not expand: \n a newlineecho 'This will not expand: \n a newline';echo '<br>';// Output : Variables do not $expand $eitherecho 'Variables do not $expand $either';echo '<br>';?>

Use double quotation marks to define the string
If the string is enclosed in double quotes (") in , PHP The following special characters will be parsed :
| Sequence | meaning |
|---|---|
\n | Line break (ASCII In the character set LF or 0x0A (10)) |
\r | enter (ASCII In the character set CR or 0x0D (13)) |
\t | Horizontal tabs (ASCII In the character set HT or 0x09 (9)) |
\v | Vertical tabs (ASCII In the character set VT or 0x0B (11)) |
\e | Escape(ASCII In the character set ESC or 0x1B (27)) |
\f | Change the page (ASCII In the character set FF or 0x0C (12)) |
\\ | Backslash |
\$ | Dollar sign |
\" | Double quotes |
\[0-7]{1,3} | What matches the regular expression sequence is a character expressed in octal ,which silently overflows to fit in a byte (e.g. "\400" === "\000") |
\x[0-9A-Fa-f]{1,2} | What matches the regular expression sequence is a character expressed in hexadecimal |
\u{[0-9A-Fa-f]+} | The sequence of characters matching the regular expression is unicode Code bits , This code bit can be used as UTF-8 The expression of the output string |
Just like a single quote string , Escaping any other character will cause the backslash to be displayed .
<?phpecho "this is a simple string";?>

Heredoc structure
The third way to express a string is to use heredoc syntactic structure :<<<. Provide an identifier after the operator , And then line break . Next is the string string In itself , Finally, use the identifier defined above as the end flag .
End identifiers can use spaces or tabs (tab) Indent , The document string removes all indents . stay PHP 7.3.0 In the previous version , The identifier referenced at the end must be in the first column of the row .
and , The naming of identifiers should also be followed like other tags PHP The rules of : Can only contain letters 、 Numbers and underscores , And must start with a letter and an underscore .
Example 1
<?php$str = <<<EOF url: https://www.yisu.com/EOF;echo $str;?>

“ stay php What is the concept of string in ” That's all for , Thanks for reading . If you want to know more about the industry, you can pay attention to Yisu cloud website , Xiaobian will output more high-quality practical articles for you !
边栏推荐
- Global and Chinese market of Kanban software 2022-2028: Research Report on technology, participants, trends, market size and share
- Unity TimeLine 数据绑定
- NPDP产品经理国际认证考试报名有什么要求?
- Cmake tutorial series -05- options and variables
- Idea remote debugging remote JVM debug
- 2.8 【 weight of complete binary tree 】
- A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022
- HTA introductory basic tutorial | GUI interface of vbs script HTA concise tutorial, with complete course and interface beautification
- Global and Chinese market for defense network security 2022-2028: Research Report on technology, participants, trends, market size and share
- Study diary: February 15, 2022
猜你喜欢

Digicert、Sectigo、Globalsign代码签名证书的区别

Raki's notes on reading paper: Leveraging type descriptions for zero shot named entity recognition and classification

Three solutions to forced hibernation of corporate computers

隐藏在科技教育中的steam元素

Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)

Several key points recorded after reviewing redis design and Implementation

如何在 JupyterLab 中把 ipykernel 切换到不同的 conda 虚拟环境?

学术汇报(academic presentation)/PPT应该怎么做?

Call collections Sort() method, compare two person objects (by age ratio first, and by name ratio for the same age), and pass lambda expression as a parameter.

SSL证书七大常见错误及解决方法
随机推荐
2.8 【 weight of complete binary tree 】
NPDP产品经理国际认证考试报名有什么要求?
Xunwei enzhipu ITop - imx6 Development Platform
A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022
Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)
Global and Chinese market of relay lens 2022-2028: Research Report on technology, participants, trends, market size and share
SSL证书七大常见错误及解决方法
What is the difference between a layer 3 switch and a layer 2 switch
Five cheapest wildcard SSL certificate brands
2022 the action of protecting the net is imminent. Things about protecting the net
JMeter obtains cookies across thread groups or JMeter thread groups share cookies
Global and Chinese market of mobile commerce solutions 2022-2028: Research Report on technology, participants, trends, market size and share
How vscode debugs into standard library files / third-party package source code
Implementation of Sanzi chess with C language
学术汇报(academic presentation)/PPT应该怎么做?
Cmake tutorial series -05- options and variables
代码签名、驱动签名的常见问题解答
What is an X.509 certificate? 10. 509 certificate working principle and application?
Unity timeline data binding
Raki's notes on reading paper: discontinuous named entity recognition as maximum clique discovery