Concatenation of two strings in PHP Last Updated : 16 Sep, 2024 Comments Improve Suggest changes Like Article Like Report In this article, we will concatenate two strings in PHP. There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side. Examples:Input : string1: Hello string2 : World! Output : HelloWorld!Input : string1: geeksfor string2: geeksOutput : geeksforgeeksExample 1: PHP <?php // First String $a = 'Hello'; // Second String $b = 'World!'; // Concatenation Of String $c = $a.$b; // print Concatenate String echo " $c \n"; ?> Output HelloWorld! Time complexity : O(n) Auxiliary Space : O(n)Example 2: PHP <?php // First String $fname = 'John'; // Second String $lname = 'Carter!'; // Concatenation Of String $c = $fname." ".$lname; // print Concatenate String echo " $c \n"; ?> Output John Carter! Time complexity : O(n) Auxiliary Space : O(n)Example 3: PHP <?php // First String $a = 'Hello'; // now $a contains "HelloWorld!" $a .= " World!"; // Print The String $a echo " $a \n"; ?> Output Hello World! Time complexity : O(n) Auxiliary Space : O(n)Example 4: PHP <?php // First String $a = 'Geeksfor'; // Second String $b = "Geeks"; // now $c contains "GeeksforGeeks" $c = "$a{$b}"; // Print The String $c echo " $c \n"; ?> Output GeeksforGeeks Time complexity : O(n) Auxiliary Space : O(n)PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples. Comment More infoAdvertise with us Next Article Concatenation of two strings in PHP A Anivesh Tiwari Follow Improve Article Tags : Misc Strings Web Technologies PHP DSA PHP-string +2 More Practice Tags : MiscStrings Similar Reads PHP | is_string() Function The is_string() function is an inbuilt function in PHP which is used to check whether the given value is a string or not. Syntax: bool is_string( mixed $var ) Parameters: This function accepts one parameter as mentioned above and described below: $var: It contains the value that need to check. Retur 1 min read How to convert an Integer Into a String in PHP ? The PHP strval() function is used to convert an Integer Into a String in PHP. There are many other methods to convert an integer into a string. In this article, we will learn many methods.Table of ContentUsing strval() function.Using Inline variable parsing.Using Explicit Casting.Using sprintf() Fun 3 min read PHP stristr() Function The stristr() function is a built-in function in PHP. It searches for the first occurrence of a string inside another string and displays the portion of the latter starting from the first occurrence of the former in the latter (before if specified). This function is case-insensitive. Syntax : strist 2 min read PHP mb_stristr() Function The mb_stristr() is an inbuilt function in PHP that is used to get the first occurrence of a string within another string. It will check case insensitivity. Syntax:mb_stristr( $haystack, $needle, $before_needle, $encoding = null ): string|falseParameters: This function accepts 4 parameters that are 2 min read PHP String Functions Strings are a fundamental data type in PHP, used to store and manipulate text. PHP provides a wide variety of built-in string functions. These functions perform various operations such as string transformations, character manipulations, encoding and decoding, and formatting, making string handling s 6 min read How to limit string length in PHP ? A string is a sequence of characters in PHP. The length of the string can be limited in PHP using various in-built functions, wherein the string character count can be restricted. Table of ContentUsing for loopUsing mb_strimwidth() function Using substr() method Using Regular Expressions with preg_m 6 min read How to get string between two characters in PHP ? A string is a sequence of characters stored in the incremental form in PHP. A set of characters, one or many can lie between any two chosen indexes of the string. The text between two characters in PHP can be extracted using the following two methods : Table of ContentUsing substr() Method: Using fo 4 min read How to insert a line break in PHP string ? In this article, we will discuss how to insert a line break in a PHP string. We will get it by using the nl2br() function. This function is used to give a new line break wherever '\n' is placed.Syntax:nl2br("string \n");where the string is the input string.Example 1: PHP Program to insert a line bre 2 min read How to write Multi-Line Strings in PHP ? Multi-Line Strings can be written in PHP using the following ways.Using escape sequencesWe can use the \n escape sequences to declare multiple lines in a string.PHP Code:PHP<?php //declaring multiple lines using the new line escape sequence $var="Geeks\nFor\nGeeks"; echo $var; ?>Output:Geeks F 2 min read How to get a substring between two strings in PHP? To get a substring between two strings there are few popular ways to do so. Below the procedures are explained with the example.Examples: Input:$string="hey, How are you?"If we need to extract the substring between "How" and "you" then the output should be are Output:"Are"Input:Hey, Welcome to Geeks 4 min read Like