PHP String Operators

In this lesson, you will learn about the two String Operations in PHP, and their usages, with examples to better understand the topic.


PHP String Operators

The Two string operators in PHP are given below.

String Operators Symbol String Operators’ Names Example
. Concatenation $a.$c ;
Concatenate a and c text values
.= Concatenation assignment $a.=$c ;
Appends c to a text value

Example

<?php
echo "PHP String Operator Example";
echo "<br>";
echo " ---------------------------------------- ";
echo "<br>";
//concatenatin with .
$a = "PHP !! ";
$c = "It is an efficient server scripting language.";
echo '1st String $a= ', $a, "<br>", '2nd String $b= ', $c;
echo "<br>";
echo 'Result of Concatenation $a.$c --> print a.c';
echo "<br>";
echo $a . $c;
echo "<br>";
echo " ---------------------------------------- ";
echo "<br>";
//Append text of 1st VARIABLE with 2nd.
$a = "PHP !! ";
$c = "It is an efficient server scripting language.";
echo '1st String $a = ', $a, "<br>", '2nd String $b = ', $c;
echo "<br>";
echo 'Result of Concatenation $a.=$c --> print a';
echo "<br>";
$a .= $c;
echo $a;
?>

Output

PHP String Operator Example
----------------------------------------
1st String $a= PHP !!
2nd String $b= It is an efficient server scripting language.
Result of Concatenation $a.$c --> print a.c
PHP !! It is an efficient server scripting language.
----------------------------------------
1st String $a = PHP !!
2nd String $b = It is an efficient server scripting language.
Result of Concatenation $a.=$c --> print a
PHP !! It is an efficient server scripting language.

This concludes the PHP String Operators lesson. In the next lesson, you will learn about the Array operation in PHP.