PHP for the World Wide Web (Visual QuickStart Guide)
I l @ ve RuBoard |
It's an unwieldy term , but a useful concept concatenation. It refers to the process of linking items together. Specifically in programming, you concatenate strings. The period (.) is the operator for performing this action, and it's used like so: $NewString = $aString . $bString. You can link as many strings as you want in this way. You can even join numbers to strings: $NewString = $aString . $bString $cNumber; This works because PHP is weakly typed, meaning that its variables are not locked in to one particular format. Here, the $cNumber variable will be turned into a string and appended to the value of the $NewString variable. Your HandleForm.php script contains strings that could logically be concatenated . It's quite common and even recommended to take a user 's first and last name as separate inputs, as you did with your form. On the other hand, it would be advantageous to be able to refer to the two together as one name . You'll modify your script with this in mind. To use concatenation in your script:
Tip Due to the nature of how PHP deals with variables, the same effect could be accomplished using $Name = "$FirstName $LastName";. This is because variables used within double quotation marks are replaced with their value when handled by PHP. However, the formal method of using the period to concatenate stringsas you did hereis more commonly used and I therefore recommend doing it that way (it will be more obvious what is occurring in your code).
Tip You could also have written $FirstName = $FirstName . " " . $LastName; but there are two reasons why you shouldn't. First, doing so would have overwritten the original value of the $FirstName variable. Second, "FirstName" would no longer be an appropriate description of the variable's value. You should always try to maintain valid variable names as you program.
|
I l @ ve RuBoard |