Forum Moderators: coopster

Message Too Old, No Replies

$var .$var $var. Something simple im sure?

         

PSWorx

11:30 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



Ok here goes:

Im using a selection of includes to produce a page template i.e.

index.php contains the following code:

<?php
$varTitle="Home";
$varSub="";

$bodyContents='<h5>Home</h5>';

include("includes/head.php");
include("includes/body.php");
include("includes/footer.php");
?>

The $bodyContents var is utilized by the body.php page which loads this data into the main content area..

NOTE:
$varTitle is for page titles and headings
$varSub is to specifiy if page is in a sub directory (if so value would be ../ - allows the images, scripts etc to be loaded).

Ok so onto the questions, ive seen here and there the use of (not entirely sure which way round) $var and $var. or .$var in this fasion:

$var="My ";
.$var="name ";
.$var="is ";
.$var="Jim.";

with

echo $var; (I think)

to output the contents of the multiple instances of $var.

Basically can anyone help me in the correct way to approach this method?

I'll close the post if i find a solution.

TIA

sned

12:21 am on Nov 2, 2005 (gmt 0)

10+ Year Member



Hello,

In this case, you would want to use .= :

$var = "My ";
$var .= "name ";
$var .= "is ";
$var .= "Jim.";

You could also throw it all in one line:

$var = "My " . "name " . $some_random_var . "is " . "Jim";

hope that helps,
-sned