php printing a message in a div [closed]
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>";
精彩评论