Home > Article > Backend Development > What does "." in php mean?
The dot "." in php means "connection", which refers to the string connector, which 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;".
The operating environment of this tutorial: windows7 system, PHP7.1 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:
Instructions: When using echo to output a string, you can also use curly brackets {$str}
to embed variables in the string, such as "literal{$str}literal
"; if you do not use { } 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:
In javascript, we can use " " to splice strings, but in PHP, the " " sign can only do arithmetic operator, but cannot be used as a string operator; then can only the "." operator be used to concatenate strings? No, you can also use the assignment operator ".=
". The
.=
operator appends the characters on the right to the left. Its syntax is:
$string = string1; $string .= string2; $string .= string3; ······ $string .= stringn;
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What does "." in php mean?. For more information, please follow other related articles on the PHP Chinese website!