测试PHP的字符串类型(string)-Part 1
2009-04-22 15:03
246 查看
下面的代码都是在PHP命令行模式下执行的。
字符串可以用两个单引号定义。
php > echo 'a string defined with single quotes';
a string defined with single quotes
字符串可以分多行来定义。
php > echo 'a string defined with single quotes
php ' but with multiple lines
php ' did you notice it?';
a string defined with single quotes
but with multiple lines
did you notice it?
如果想在单引号定义的字符串里嵌入单引号,需要用反斜杠转义。
php > echo 'if you need to embed single quote in such a string, use slash. like /'';
if you need to embed single quote in such a string, use slash. like '
如果想在单引号定义的字符串里嵌入双引号,没有特别需要处理的。只要像使用一般字符一样就可以了。
php > echo 'if you need to embed double quote in such a string, just use it as other characters like "hello"';
if you need to embed double quote in such a string, just use it as other characters like "hello"
如果想在单引号定义的字符串里嵌入反斜杠,且反斜扛是最后一个字符,那就用两个反斜杠。
php > echo 'if backslash is the last character, then double it like//';
if backslash is the last character, then double it like/
如果想在单引号定义的字符串里嵌入反斜杠,而反斜扛不是最后一个字符,那可以用一个反斜杠或者两个反斜杠,其结果都是输出一个反斜杠。
php > echo 'if backslash is NOT the last character, then just use it like / or //.';
if backslash is NOT the last character, then just use it like / or /.
字符串可以用两个单引号定义。
php > echo 'a string defined with single quotes';
a string defined with single quotes
字符串可以分多行来定义。
php > echo 'a string defined with single quotes
php ' but with multiple lines
php ' did you notice it?';
a string defined with single quotes
but with multiple lines
did you notice it?
如果想在单引号定义的字符串里嵌入单引号,需要用反斜杠转义。
php > echo 'if you need to embed single quote in such a string, use slash. like /'';
if you need to embed single quote in such a string, use slash. like '
如果想在单引号定义的字符串里嵌入双引号,没有特别需要处理的。只要像使用一般字符一样就可以了。
php > echo 'if you need to embed double quote in such a string, just use it as other characters like "hello"';
if you need to embed double quote in such a string, just use it as other characters like "hello"
如果想在单引号定义的字符串里嵌入反斜杠,且反斜扛是最后一个字符,那就用两个反斜杠。
php > echo 'if backslash is the last character, then double it like//';
if backslash is the last character, then double it like/
如果想在单引号定义的字符串里嵌入反斜杠,而反斜扛不是最后一个字符,那可以用一个反斜杠或者两个反斜杠,其结果都是输出一个反斜杠。
php > echo 'if backslash is NOT the last character, then just use it like / or //.';
if backslash is NOT the last character, then just use it like / or /.
相关文章推荐
- php开发笔记(三)字符串(string)类型中单双引号使用的注意事项
- php使用redis-数据类型为字符串类型(String)
- 泛编程中关于std::string类型字符串长度大于预留空间与小于预留空间之间互相转换的探索测试
- PHP基础之数据类型4——字符串(String)
- PHP手册-语言参考-类型-String 字符串
- Javascript基础教程之数据类型 (字符串 String)
- 在c++Builder中使用boost正则表达式实现的查找double和int类型的字符串,并实现StringToInteger和StringToDouble函数
- PHP把下划线分隔命名的字符串转换成驼峰式命名方式(带10万次执行效率测试结果)
- Android应用资源---字符串资源类型(String)
- C风格字符串,int型,string类型相互转换
- Delphi中string数据类型的特殊用法(获取string字符串的单个字符)
- Python 中的基本数据类型 ---Number(数字) 和 String(字符串)
- PHP中将字符串转化为整数(int) intval() printf() 性能测试
- 我刚刚写了一个map的题目,还用到了#include<string>的头文件,下面我来总结一下 map<类型>变量 q q.find(找字符串) q.end()是否到达末尾
- Redis笔记3:数据类型之字符串(String)
- 如果不空null并且不是空字符串才去修改这个值,但这样写只能针对字符串(String)类型,如果是Integer类型的话就会有问题了。 int i = 0; i!=''。 mybatis中会返回tr
- php 计算字符串长度时间测试
- C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- flex4 日期类型字符串转日期类型(string转Date)
- Oracle中Clob类型的字段数据转换成String字符串