Hi to all my question is some weird but i'll explane in here.
i want to record cv examples and user informations. i have two table like that;
cv
*id *format
users
*id *name *age
in format cell include some html tags and $name , $age tags like that;
<p>
My name is <b>$name</b> and im <b>$age</b> years old.
<p>
my codes are like that;
$sqlcv = mysql_fetch_array(mysql_query("select * from cv where id='2'"));
$text = $sqlcv['format'];
$sqluser = mysql_fetch_array(mysql_query("select * from users where id='3'"));
$name = $sqluser['name'];
$age = $sqluser['age'];
echo $text;
result; My name is and im years old. ,现年 。 so html tags works but name and age not shown :( hope i can explane this one
您可以使用sprintf()
echo sprintf("Hi im %s and im %d years old.", "Darius", $age);
Try this:
$age = 23;
$text = "Hi im Darius and im ".$age." years old";
echo $text;
You have to write $text like this:
$text = "Hi im Darius and im " . $age . " years old";
Else it will think $age is in the string.
<p>My name is <b>$name</b> and I'm <b>$age</b> years old.<p>
I can't tell from your question, but you might have forgotten to wrap it in php. If that's the case, try using
<?php echo "<p>My name is <b>$name</b> and I'm <b>$age</b> years old.<p>"; ?>
or
<p>My name is <b><?=$name?></b> and I'm <b><?=$age?></b> years old.<p>
OR if you actually have the string "<p>My name is <b>$name</b> and I'm <b>$age</b> years old.<p>" in the database cell (I hope you don't) and want to replace the variables with custom values, I suggest using
$output = str_replace('$age', $yourAgeVariable, $theCellValue)
and similarly with $name. I think that wouldn't make sense to put that into a database column though, so I'm posting this other part just in case you actually did that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.