[英]How do i echo variable inside html
I have an html image-background code which I like to output $cartTotal
in it.我有一个 html 图像背景代码,我喜欢在其中输出
$cartTotal
。 My problem is: how do I echo variable $cartTotal
inside the html code?我的问题是:如何在 html 代码中回显变量
$cartTotal
?
I have tried:我试过了:
<?php echo'<TABLE BORDER="0" cellpadding="0" CELLSPACING="0"> <TR> <TD WIDTH="60" HEIGHT="70" BACKGROUND="inventory_images/3.jpg" VALIGN="bottom"> <FONT SIZE="+5" COLOR="red"><?php
echo "$cartTotal";
?></FONT></TD> </TR> </TABLE>'; ?>
But it returns $cartTotal
instead of the expected output.但它返回
$cartTotal
而不是预期的输出。
echo
inside echo
will not work, Just put variable name inside echo
echo
里面的echo
不起作用,只要把变量名放在echo
里面
<?php
echo '<TABLE BORDER="0" cellpadding="0" CELLSPACING="0">
<TR>
<TD WIDTH="60" HEIGHT="70" BACKGROUND="inventory_images/3.jpg" VALIGN="bottom">
<FONT SIZE="+5" COLOR="red">'.$cartTotal.'</FONT>
</TD>
</TR>
</TABLE>';
?>
Also check some other example : https://eval.in/868385还要检查一些其他示例: https : //eval.in/868385
Don't write PHP
inside PHP
.不要写
PHP
内PHP
。 change your code to:将您的代码更改为:
<?php echo'<TABLE BORDER="0" cellpadding="0" CELLSPACING="0"> <TR> <TD WIDTH="60"
HEIGHT="70" BACKGROUND="inventory_images/3.jpg" VALIGN="bottom"> <FONT SIZE="+5"
COLOR="red">'.$cartTotal.'</FONT></TD> </TR> </TABLE>'; ?>
<TABLE BORDER="0" cellpadding="0" CELLSPACING="0"> <TR> <TD WIDTH="60" HEIGHT="70" BACKGROUND="inventory_images/3.jpg" VALIGN="bottom"> <FONT SIZE="+5" COLOR="red"> <?php echo $cartTotal; ?> </FONT> </TD> </TR> </TABLE>
Try this code:试试这个代码:
This might work.这可能会奏效。 You have not closed the single quote, so closing the quote, and concatenating the variable (using the dot) should have the desired result.
您尚未关闭单引号,因此关闭引号并连接变量(使用点)应该会得到所需的结果。
<?php echo '<TABLE BORDER="0" cellpadding="0" CELLSPACING="0"> <TR> <TD WIDTH="60" HEIGHT="70" BACKGROUND="inventory_images/3.jpg" VALIGN="bottom"> <FONT SIZE="+5" COLOR="red">' . $cartTotal . '</FONT></TD> </TR> </TABLE>'; ?>
Alternatively, you could put normal HTML with just the short-tag echo statement:或者,您可以仅使用短标签 echo 语句放置普通 HTML:
<TABLE BORDER="0" cellpadding="0" CELLSPACING="0">
<TR> <TD WIDTH="60" HEIGHT="70" BACKGROUND="inventory_images/3.jpg" VALIGN="bottom"> <FONT SIZE="+5" COLOR="red">
<?=$cartTotal?>
</FONT></TD> </TR> </TABLE>
You Can try this你可以试试这个
<?php
echo"<TABLE BORDER='0' cellpadding='0' CELLSPACING='0'>";
echo"<TR>";
echo"<TD WIDTH='60' HEIGHT='70' BACKGROUND='inventory_images/3.jpg' VALIGN='bottom'> ";
echo"<TD WIDTH='60' HEIGHT='70' BACKGROUND='inventory_images/3.jpg' VALIGN='bottom'> ";
echo $cartTotal;
echo"</FONT></TD> </TR> </TABLE> "; ?>
Your problem is that you are echoing inside of a single quoted string which doesn't work.您的问题是您在一个不起作用的单引号字符串中回显。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.