In this tutorial we will learn How To Prepend a String in PHP. We can use PHP concatenation operator or dot operator to prepend a string in PHP.
Table of Contents
Using Concatenation Operator (.)
We can simply use Concatenation Operator (.) to Prepend a string in PHP.
No need to use any function or method for this.
Take a look at the code given below.
<?php
$string1 = 'Hello';
$string2 = 'World!';
$newString = $string1 . $string2;
?>
This will simply prepend a string with other one but without space obviously.
To add space between two strings we can do something like this.
<?php
$string1 = 'Hello';
$string2 = 'World!';
$newString = $string1 . ' ' . $string2;
?>