PHP string concatenation


Home - Tutorials - Basics

In this small article I will show you how to use PHP string concatenation possibilities.

Tutorial info:


Name:PHP string concatenation
Total steps:1
Category:Basics
Level:Beginner

Bookmark PHP string concatenation



Bookmark and Share

Step 1 - PHP string concatenation


PHP string concatenation

String concatenation is the string manipulation method when you join 2 or more strings together. In PHP it is a quite easy task. You can use the concatenation operator which is the '.' (dot). You can join 2 or more strings into one as follows:

Code:
  1. <?php
  2. $str1 = 'This ';
  3. $str2 = 'is a ';
  4. $str3 = 'test string';
  5.  
  6. $full = $str1.$str2.$str3;
  7.  
  8. echo $full;
  9. ?>

Besides this you can use the operator to append a string to an existing one like this:

Code:
  1. <?php
  2. $str = 'This is the base string';
  3. $str .= ' and this was appended';
  4.  
  5. echo $str;
  6. ?>

If you concatenate a number with a string then the number will be converted into a string value so the output will be a string as follows:

Code:
  1. <?php
  2. $i = 100;
  3. $str = $i.' is a number';
  4.  
  5. echo $str;
  6. ?>

 







Tags: php string concatenation, php string concat, string concatenation

PHP string concatenation - Table of contents
Step 1 - PHP string concatenation


Follow phpf1 on Twitter




F1 Site Family
AJAX F1
CSS F1
Database F1
Flash F1
HTML F1
Java F1
JavaScript F1
PhotoShop F1
PHP F1
Scripts F1
Tutorial F1
Windows F1

Total time: 0.0976