当前位置:网站首页>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 !
边栏推荐
- Multi card server usage
- Intel-Hex , Motorola S-Record 格式详细解析
- CMake教程系列-02-使用cmake代码生成二进制
- 学术汇报(academic presentation)/PPT应该怎么做?
- 银行的理财产品一般期限是多久?
- Pytorch学习(二)
- JMeter obtains cookies across thread groups or JMeter thread groups share cookies
- Heavy attack -- ue5's open source digital twin solution
- 【干货分享】最新WHQL徽标认证申请流程
- FDA ESG regulation: digital certificate must be used to ensure communication security
猜你喜欢

Idea remote debugging remote JVM debug

Wechat applet page Jump and parameter transfer

Série de tutoriels cmake - 02 - génération de binaires à l'aide du Code cmake

NPDP产品经理国际认证考试报名有什么要求?

Some configuration details about servlet initial development

PR second training notes

oracle怎么设置密码复杂度及超时退出的功能

Pytoch learning (II)

Pytorch学习(二)

2022年7月深圳地区CPDA数据分析师认证
随机推荐
NPDP产品经理国际认证考试报名有什么要求?
Select sort
如何预防钓鱼邮件?S/MIME邮件证书来支招
SSL证书七大常见错误及解决方法
Enlightenment from the revocation of Russian digital certificate by mainstream CA: upgrade the SSL certificate of state secret algorithm to help China's network security to be autonomous and controlla
Mysql表数据比较大情况下怎么修改添加字段
Global and Chinese market of Kanban software 2022-2028: Research Report on technology, participants, trends, market size and share
FDA mail security solution
HTA introductory basic tutorial | GUI interface of vbs script HTA concise tutorial, with complete course and interface beautification
Raki's notes on reading paper: named entity recognition as dependency parsing
VScode如何Debug(调试)进入标准库文件/第三方包源码
Recursion frog jumping steps problem
福利抽奖 | 开源企业级监控Zabbix6.0都有哪些亮点
CMake教程系列-03-依赖管理
CMake教程系列-04-编译相关函数
Heap sort
怎么使用Vant实现数据分页和下拉加载
Global and Chinese market of mobile commerce solutions 2022-2028: Research Report on technology, participants, trends, market size and share
选购通配符SSL证书注意事项
CMake教程系列-01-最小配置示例