How to use the strcat Function In PHP
The strcat is not a native function in PHP, the equivalent operation can be achieved using the concatenation operator (.). The example shows $newstr = $oldstr. ” w3wiki”; defines the concatenation of two strings.
Example: The below method illustrates how to add a Character to a String in PHP with the help of strcat Function.
PHP
<?php $oldstr = "Hello," ; $newstr = $oldstr . " w3wiki !!" ; echo $newstr ; ?> |
Output:
Hello, w3wiki !!
How to add a Character to String in PHP ?
Given two strings, the task is to add a Character to a String in PHP. The character can be added to a string in many ways in this article we will be using eight methods including the Concatenate Method, the String Interpolation Method, the str_pad() Method, Concatenation Assignment (.=) Operator, String Conversion, The sprintf Function or printf Function, The strcat Function, and Using Array Join.
For Example, Consider the below example where there are two strings:
Input string1 = "Welcome to" , string2 = "w3wiki" Output Welcome to w3wiki
Table of Content
- Using Concatenate Method
- Using String Interpolation Method
- Using str_pad() Method
- Using the Concatenation Assignment (.=) Operator
- Using the String Conversion
- Using the sprintf Function or printf Function
- Using the strcat Function
- Using Array Join
Contact Us