variable substitution
Several ways to do this (and avoid globals or a str_replace call):
#1:
if (condition)
{
$string_b = 'blah';
} else if (condition2)
{
$string_b = 'foo';
} else if (condition3)
{
$string_b = 'bar';
} else
{
$string_b = 'other';
}
$string_a = "stuff $string_b and more stuff";
The reason for this is the variable substition occurs *at the time of
assignment* - not later.
Another way, if it's not easy to have your string_b setting
conditionals all in a row like that (or if this needs to be done
elsewhere in code, as well), would be:
function assignStrA($subStr)
{
$retVal = "stuff $subStr and more stuff";
return $retVal;
}
if (cond1)
{
$string_a = assignStrA('foo');
} else if (cond2)
{
$string_a = assignStrA('bar');
} else
{
$string_a = assignStrA('other');
}
HTH-
James Ausmus
Integration Software Engineer
HTRI
"Cross Technology Integration Specialists" 503-538-8085
|