Home > Backend Development > PHP Problem > What does php dot mean?

What does php dot mean?

青灯夜游
Release: 2023-03-18 06:24:01
Original
3115 people have browsed it

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".

What does php dot mean?

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;
Copy after login

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;
?>
Copy after login

Output result:

What does php dot mean?

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}";
?>
Copy after login

Output result:

What does php dot mean?

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;
Copy after login

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;
?>
Copy after login

Output results:

What does php dot mean?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template