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:

<?php
/* File: ch05ex01.php – demonstrates string concatenation */?>
<html>
<head><title>Pela PHP tutorial :: The String Concatenation Operator :: Example </title></head>
<body>
<?php
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”>
</form>
</body>
</html>

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 3707
  1. Add New Comment