In PHP, dot "." means "connection" or "splicing". It is a string connector that can be used to splice two or more strings together to form A new string; the specific syntax format is "$string = $string1.$string2.$string3. ······ .$stringN;". In addition to using "." strings to concatenate strings, there is also the assignment operator ".=" and the syntax "$string1 .= $string2".
The operating environment of this tutorial: windows7 system, PHP8 version, DELL G3 computer
In php, click ".
" refers to the string concatenation character, which can splice two or more strings into a new string.
The specific syntax format is as follows:
$string = $string1.$string2.$string3. ······ .$stringN;
Example:
<?php header("Content-type:text/html;charset=utf-8"); $str1="欢迎来到"; $str2="PHP中文网"; $str3=$str1.$str2; echo "字符串1:".$str1; echo "<br>字符串2:".$str2; echo "<br>字符串1和字符串2拼接后:".$str3; ?>
Output result:
You can see When we use echo for output, we sometimes need some text prompts. At this time, we can use the string concatenator to splice the text strings and variables surrounded by quotation marks together for output, such as the "echo " character After concatenating string 1 and string 2: ".$str3;
".
Note:
When using echo to output a string, you can also use curly brackets
{$str}
to embed variables in the string, such as "Text {$str}Text
"; If {} is not used, you can also use word segmentation characters to separate variables and text. Word segmentation characters are generally spaces, punctuation marks, etc.
<?php header("Content-type:text/html;charset=utf-8"); $str1="欢迎来到"; $str2="PHP中文网"; $str3=$str1.$str2; echo "字符串1:".$str1; echo "<br>字符串2:$str2"; echo "<br>字符串1和字符串2拼接后: {$str3}"; ?>
Output result:
Extended knowledge: use assignment operator.=
Except Use the "." operator to concatenate strings, and you can also use the assignment operator ".=
" to concatenate strings.
In PHP, you can use the format of "$string1 .= $string2
" to concatenate strings. The
.=
operator appends the characters on the right to the left. Its syntax is:
$string = string1; $string .= string2; $string .= string3; ······ $string .= stringn;
Let’s take a look at the following example to understand the .=
operator.
<?php header("Content-type:text/html;charset=utf-8"); $str1="欢迎来到"; echo "字符串1:".$str1; $str2="PHP中文网"; echo "<br>字符串2:".$str2; $str1.=$str2; echo "<br>字符串1和字符串2拼接后:".$str1; ?>
Output results:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What does php dot mean?. For more information, please follow other related articles on the PHP Chinese website!