The String Concatenation Operator

Sep 30, 2009 Author: Developer

The following program asks the user for his first and last names, then prints his full name in two different formats:

/* File: ch05ex01.php – demonstrates string concatenation */?>
<head><title>Pela PHP tutorial :: The String Concatenation Operator :: Example </title></head>
if ($HTTP_GET_VARS[‘fname’] && $HTTP_GET_VARS[‘lname’])
echo $HTTP_GET_VARS[‘fname’] . ‘ ‘ . $HTTP_GET_VARS[‘lname’] . ‘<br>’;
echo $HTTP_GET_VARS[‘lname’] . ‘, ‘ . $HTTP_GET_VARS[‘fname’] . ‘<br>’;
<form action=”ch05ex01.php” method=”GET”>
First Name: <input type=”text” name=”fname”><br>
Last Name: <input type=”text” name=”lname”><br>
<input type=”submit”>

Being able to join two strings in this manner expands the flexibility of your program. Because you know that this is possible, you can ask for first and last names separately, and, in turn, have the ability to manipulate that name however you want.

views 4298
  1. Add New Comment