About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Strings - Connecting...

   Browse by title articles:
   What is hot:

Numbers - Random

Strings - Connecting

Strings - Pulling apart

if/elseif/else

switch/case

while/do while

Building Link Popularity
File Permissions
Usability and Cost Savings while Designing an Intranet
Graphics for the web: JPG and PNG Files
Prev articles123456 7 89101112Next articles



Strings - Connecting


Computer & I'net articlesStrings - Connecting

by David Stanley    



Connecting strings together is known as concatenation. The operator to use with this is the period.

$NewString = $string1 . $string2;

The value of $NewString is the combination of $string1 and $string2. This is not addition like in math. This is taking the value of $string2 and plunking it onto the end of $string1.

<?php
$string1 = "This is an example";
$string2 = "of connecting strings.";
$NewString = $string1 . $string2;
echo "$NewString";
?>

This is an exampleof connecting strings.

Hmmm... that doesn't quite look right. There should be a space between the words example and of. Let's add in a space on the connecting code line :

$NewString = $string1 . " " . $string2;

This is an example of connecting strings.

So you can add strings, direct quoted data, and so forth together. Some "real world" example of using this may be to combine a $FirstName and $LastName into one string. There could be many other uses as well.




-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.





Interest compare




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com