We have given two strings and the task is to prepend a string str1 with another string str2 in PHP. There is no specific function to prepend a string in PHP. In order to do this task, we have the following operators in PHP:
Method 1: Using Concatenation Operator(“.”): The Concatenation operator is used to prepend a string str1 with another string str2 by concatenation of str1 and str2.
$x . $y
Method 2: Using Concatenation assignment operator (“.=”): The Concatenation assignment operator is used to prepend a string str1 with another string str2 by appending the str2 to the str1.
$x .= $y
- HTML | DOM ParentNode.prepend() Method
- How to check a string starts/ends with a specific string in jQuery ?
- PHP | Program to check a string is a rotation of another string
- What is the difference between 'String' and 'string' in TypeScript ?
- ES6 | String
- PHP | String Functions
- TypeScript String
- How to get parameters from a URL string in PHP?
- PHP | Different characters in the given string
- How to get the last n characters of a PHP string?
- How to append a string in PHP ?
- PHP | Reverse a String
- ES6 | New String Methods
- How to check if URL contain certain string using PHP?
- How to get a variable name as a string in PHP?
- PHP to check substring in a string
- How to convert a string into number in PHP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.