String Variables

String variables are variables that contain text (characters).

PHP has many functions that can help you manipulate the string you have created.

Joining strings together
In PHP you can join two or more string together very easily. You can do this by using a dot (” . “).

In the example below, I’ve declared two strings and in the third string I have joined the first two together.

[php]
<?php
$string1 = "Hey there ";
$string2 = "How are you?";

$string3 = $string1.$string2;
?>
[/php]

$string3 will now equal to “Hey there How are you?”.

Here’s another example of joining strings. In this example, I have declared two strings and then joined the first string onto the end of the second string.

[php]
<?php
$string1 = "hot";
$string2 = "Today is so ".$string1;
?>
[/php]

$string2 will now equal to “Today is so hot”.

Another example
[php]
<?php
$txt1="Hello World!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2;
?>
[/php]
The output on screen will be:

Hello World! What a nice day!