![]() |
VOOZH | about |
We have given two strings and the task is to append a string str1 with another string str2 in PHP. There is no specific function to append a string in PHP. In order to do this task, we have the this operator in PHP:
Table of Content
The Concatenation assignment operator is used to append a string str1 with another string str2.
Syntax:
$x .= $yExample :
GeeksforGeeks
The Concatenation operator is used to append a string str1 with another string str2 by concatenation of str1 and str2.
Syntax:
$x . $y
Example :
GeeksforGeeks
Using double quotes with variables (interpolation) in PHP allows you to embed variables directly within a string. PHP automatically replaces the variable with its value.
Example:
Hello, world!
The sprintf() function in PHP can be used to format and append strings by specifying a format string that includes placeholders for variables. This method allows for more complex string manipulations and formatting.
Example:
Hello, World!
The implode() function in PHP can be used to concatenate elements of an array into a single string, effectively appending multiple strings together.
Example:
Hello World!
The str_replace function in PHP can be used to replace all occurrences of a search string with a replacement string. By using a placeholder, we can effectively append one string to another.
In this approach:
Example:
Hello, World!
The array_merge function can be used to merge arrays, and by combining it with the implode function, we can concatenate multiple strings into a single string.
Example:
Hello World!