开发者

php printing a message in a div [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this qu开发者_如何学Cestion so that it can be reopened, visit the help center. Closed 11 years ago.

Can I have someone watch this for me? I want to echo $msg in this div.

$msg = "five";
$msg1 = "<div class='warning'><img src='images/warning_icon.png' alt='Information' width='32' height='29' class='icon' /><strong>Warning:</strong>you've added <?php echo $msg; ?> number of products<a href='#' class='close_notification' title='Click to Close' onclick='this.parentNode.parentNode.removeChild(this.parentNode);'><img src='images/close_icon.gif' width='6' height='6' alt='Close' /></a></div>";  


This will be okay.

$msg1 = "<div class='warning'>
<img src='images/warning_icon.png' alt='Information' width='32' height='29' class='icon' />
<strong>Warning:</strong>you've added " . $msg . " number of products<a href='#' class='close_notification' title='Click to Close' onclick='this.parentNode.parentNode.removeChild(this.parentNode);'>
<img src='images/close_icon.gif' width='6' height='6' alt='Close' /></a>
</div>";  

The problem was you mixed php with php when you placed <?php... inside of the string $msg1.


I'm not sure I understood, but it looks like you might just need

echo "<div>$msg</div>";

You might also want to take a look at this introductory page on strings: http://www.w3schools.com/PHP/php_string.asp


You are attempting to echo a php command in php (in msg1 you have in the string. As you are using double quotes you can include php variables in the string).

Change your code to:

$msg1 = "<div class='warning'><img src='images/warning_icon.png' alt='Information' width='32' height='29' class='icon' /><strong>Warning:</strong>you've added $msg number of products<a href='#' class='close_notification' title='Click to Close' onclick='this.parentNode.parentNode.removeChild(this.parentNode);'><img src='images/close_icon.gif' width='6' height='6' alt='Close' /></a></div>";


$msg = "five";
$msg1 = "<div class='warning'><img src='images/warning_icon.png' alt='Information' width='32' height='29' class='icon' /><strong>Warning:</strong>you've added ".$msg." number of products<a href='#' class='close_notification' title='Click to Close' onclick='this.parentNode.parentNode.removeChild(this.parentNode);'><img src='images/close_icon.gif' width='6' height='6' alt='Close' /></a></div>";  


$msg = "five";
$msg1 = "<div class='warning'><img src='images/warning_icon.png' alt='Information' width='32' height='29' class='icon' /><strong>Warning:</strong>you've added". $msg ."number of products<a href='#' class='close_notification' title='Click to Close' onclick='this.parentNode.parentNode.removeChild(this.parentNode);'><img src='images/close_icon.gif' width='6' height='6' alt='Close' /></a></div>"; 


You have <?php echo $msg; ?> inside a php script. you only need to use <?php once to tell the parser that it's a php script.

$msg = "five";
$msg1 = "<div class='warning'><img src='images/warning_icon.png' alt='Information' width='32' height='29' class='icon' /><strong>Warning:</strong>you've added $msg number of products<a href='#' class='close_notification' title='Click to Close' onclick='this.parentNode.parentNode.removeChild(this.parentNode);'><img src='images/close_icon.gif' width='6' height='6' alt='Close' /></a></div>";  


use this {$msg}

$msg = "five";
echo $msg1 = "<div class='warning'><img src='images/warning_icon.png' alt='Information' width='32' height='29' class='icon' /><strong>Warning:</strong>you've added {$msg} number of products<a href='#' class='close_notification' title='Click to Close' onclick='this.parentNode.parentNode.removeChild(this.parentNode);'><img src='images/close_icon.gif' width='6' height='6' alt='Close' /></a></div>";  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜