字符串变量类型
[rps-include post=6522]
[rps-include post = 6522]
Php have variable type string
to store text,char or string values. String type generally used to store values like name, surname, explanations, address, questions. String variables do not have any size or length limit theoretically. The only limit is the system memory limit. String can be defined in two ways like below.
PHP具有变量类型的string
来存储文本,字符或字符串值。 字符串类型通常用于存储值,例如名称,姓氏,说明,地址,问题。 理论上,字符串变量没有大小或长度限制。 唯一的限制是系统内存限制。 可以通过以下两种方式定义字符串。
- Single Quote 单引号
- Double Quote双引号
单引号(Single Quote)
Single quote string definition is very the same of double quote string definition. In this example we will define string variable named $city
in a single quote.
单引号字符串定义与双引号字符串定义非常相同。 在此示例中,我们将在单引号中定义名为$city
字符串变量。
$city='Ankara';
双引号 (Double Quote)
Double quote is similar to the single quote but there is one crucial difference. Other variables or expressions can be using in double quote string. Now first look howto use double quote to define a string.
双引号与单引号相似,但有一个关键区别。 其他变量或表达式可以在双引号字符串中使用。 现在首先看看如何使用双引号定义一个字符串。
$city = "Ankara";
Now as we stated previously use variable named $city
in new double quote string definition. New string variable will be $sentence
and will include $city variable value inside it.
现在,正如我们之前所说,在新的双引号字符串定义中使用名为$city
变量。 新的字符串变量将是$sentence
并且其中将包含$ city变量值。
$sentence="I live in $city";
echo $sentence;
This will output following line.
这将输出以下行。
I live in Ankara
多行字符串 (Multi Line String)
String generally defined as single line an short length. But in some situations we may need to define multi line strings. This is very easy where we will just use multi line in single or double quote like below. Both single and double quote can be used to define multi line string.
字符串一般定义为单行长度较短。 但是在某些情况下,我们可能需要定义多行字符串。 这是非常容易的,我们将在单引号或双引号中使用多行,如下所示。 单引号和双引号均可用于定义多行字符串。
echo 'Hello World
poftut.com
Test';
转义序列 (Escape Sequences)
While interacting with string we may need some control or escape secuence characters. These characters are used to insert some special functions. Here the list of escape sequence characters.
在与字符串交互时,我们可能需要一些控制或转义安全字符。 这些字符用于插入一些特殊功能。 这里是转义序列字符的列表。
\n
is used for new line\n
用于换行\r
is used for carriage return\r
用于回车\t
is used for tab\t
用于制表符\$
is used for dollar sign\$
用于美元符号\"
is used for double quote in string\"
用于字符串中的双引号\\
is used for backslash in string\\
用于字符串中的反斜杠
Here is some example about them.
这是有关它们的一些示例。
echo "This is new line \n";
echo "This is carriage return\r\n";
echo "This is \t a tab\n";
echo "This is \$ sign\n";
echo "This is \"double quote\"\n";
echo "This is \\ backslash\n";
And this code will output like below.
并且此代码将如下输出。
字符串串联 (String Concatenation)
The last topic about string is string concatenation. Actually we will look string related operations in detail next chapter but concatenation is important and useful operation. Concatenation can be done with point .
operator like below.
关于字符串的最后一个主题是字符串串联。 实际上,我们将在下一章详细介绍与字符串相关的操作,但是连接是重要且有用的操作。 可以使用point进行串联.
运算符如下。
In this example we concatenate two string variables named $name
and $surname
by delimiting them with a single space which concatenated between them.
在此示例中,我们通过用两个空格之间的单个空格定界来连接两个名为$name
和$surname
的字符串变量。
$name="İsmail";
$surname="Baydan";
$ fullname = $name." ".$surname;
echo $fullname;
The output will be like below.
输出将如下所示。
İsmail Baydan
[rps-include post=6522]
[rps-include post = 6522]
字符串变量类型