Forum Moderators: coopster
function getString(){
return "all the way a goal to me $a";
}function output(){
$a = 45;
$string = getString();
echo $string;
}
The output is: all the way a goal to me
I'd like it to be: all the way a goal to me 45
Obviously $a isn't in scope when the string is created but is there a clever way around this?
function getString($a, $name){
dbOpen();
$query = "select data from MyTable where name = '$name'";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
mysql_free_result($result);
dbClose();
return $row[0];
}
function output(){
$a = 45;
$string = getString($a, 'cool_name');
echo $string;
}
The MySQL query returns a string:
data, data everywhere $a
The output is: data, data everywhere $a
I'd like it to be: data, data everywhere 45
Thanks again.
$string = str_replace('$a', $a, $string);