<?php
$total=3;
echo '
<div class="idsdiv"><a href="profile.php?id=$开发者_StackOverflow中文版total">.$total.</a><div> ';
?>
i want to appear $total variable number in the link.why is this script not working?
Enclose the whole string with double quotes to embed variables inside:
echo "<div class=\"idsdiv\"><a href=\"profile.php?id=$total\">$total</a><div>";
You need to use double quotes around your HTML and single quotes around your attributes or do this...
echo '<div class="idsdiv"><a href="profile.php?id=' . $total .'">' . $total . '</a><div> ';
PHP doesn't process variable names in strings enclosed in single quotes.
<?php
$total=3;
echo '<div class="idsdiv"><a href="profile.php?id=',$total,'">',$total,'</a><div>';
?>
Look at the string section of php.net (http://php.net/string) they talk about how to use each of the types. One of quote being the ' where nothing is parsed.
<?php $total=3;
echo "<div class=\"idsdiv\"><a href=\"profile.php?id=$total\">$total</a><div> ";
?>
you had errors with your quotes
You can print HTML without printing it, like so:
<?php
$total = 3;
?>
<div class="idsdiv"><a href="profile.php?id=<?php echo $total; ?>"><?php echo $total; ?></a></div>
When I still did PHP, I found it much easier to manage than escaping tons of quotes and things like that.
You can even do it inside of an if
block too:
<?php
if ($foo == 'bar') {
?>
<div>Foo is bar</div>
<?php
}
?>
The method I like is
<?php
$total=3;
echo "<div class='idsdiv'><a href='profile.php?id={$total}'>{$total}</a><div>";
?>
It is my method, but there are plenty of ways to do it. Maybe even too many. If you want more information you can always refer to the documentation.
<?php
$total=3;
echo '<div class="idsdiv"><a href="profile.php?id=$total">'.$total.'</a><div>';
?>
You're quote are missing before and after the $total
精彩评论