linuxStat PHP Documentation

String Concatenation in PHP

To concatenate two strings use the dot (.) operator.
For example, "Dell server and " . "HP laptop"
creates a new string "Dell server and HP laptop"


Escape character in PHP

The backslash character (\) is known as escape character.
A character appearing after \ has a special meaning inside a string.
For example, \n stands for the end of line character.
\t stands for the tab character.
\\ stands for the backslash \ character.
\$ stands for the dollar $ character.

Braces inside PHP Strings

A pair of braces ({ }) in a double quoted string has a special meaning.
It is used to enclose a PHP variable. This prevents ambiguous interpretation.

An example PHP program embedded in an HTML document:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<title>Executed on Dell Server, Intel Processor, created on HP laptop</title>
</head>
<body bgcolor="#0F243E" text="#FFFF00" lang=EN-US>
<font size="5">
<?php
# An example of string variables and concatenation.
$myServer = "Dell server and ";
$myLaptop = "HP laptop";
$myServerAndLaptop = $myServer . $myLaptop;
print "{$myServer} concatenated with '$myLaptop' makes '$myServerAndLaptop'<br>";
# This is how backslash works.
print "\$myServerAndLaptop \\ \$myServer \\ \$myLaptop are string variables.<br>";
?>
</font>
</body>
</html>

Click the following link to execute the above PHP program
by my server's PHP interpreter.

Try the above example    Next    Index