What does a period character (.) Mean if it is used in the middle of a php line?

I am new to PHP, but I can not find a solution to this issue in google.

Here is a sample code:

$headers = 'From: webmaster@example.com ' . "\r\n" . 'Reply-To: webmaster@example.com ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); 

What does the period character in the middle of each part of the line do?

namely: "blabla." "blabla." "Blablalba";

+7
source share
3 answers

This operator is used to concatenate strings.

EDIT

Well, more precisely, if the value is not a string, it must be converted to one. See Convert to String for more details.

Unfortunately, this is sometimes misused to make things harder to read. Well used here:

 echo "This is the result of the function: " . myfunction(); 

Here we combine the output of the function. This is normal because we have no way to do this using the standard inline string syntax. A few ways to misuse:

 echo "The result is: " . $result; 

Here you have a variable called $result , which we can embed in a string:

 echo "The result is: $result"; 

Others find it difficult to misuse:

 echo "The results are: " . $myarray['myvalue'] . " and " . $class->property; 

This is a little tricky if you are not aware of the escape sequence {} for inserting variables:

 echo "The results are: {$myarray['myvalue']} and {$class->property}"; 

Example:

 $headers = 'From: webmaster@example.com ' . "\r\n" . 'Reply-To: webmaster@example.com ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); 

This is a bit more complicated because if we do not use the concatenation operator, we can send a new line randomly, so this forces the lines to end with "\ r \ n". I find this a more unusual case due to email header restrictions.

Remember that these concatenation operators fail, making things a little harder to read, so use them only when necessary.

+10
source

This is the concatenation operator. It concatenates two lines together. For example:

 $str = "aaa" . "bbb"; // evaluates to "aaabbb" $str = $str . $str; // now it "aaabbbaaabbb" 
+6
source

It is a concatenation operator , combining both lines together (making one line of two separate lines).

+4
source

All Articles