PHP中的CSS回声

con*_*r.p 1 css php

我遇到以下代码问题:

$submit = $_POST['submit'];
$answer = "8";
$input = strip_tags($_POST['input']);
if ($submit){ 
    if ($input==$answer){
        echo "Correct";
    }
else
    echo "Wrong";
Run Code Online (Sandbox Code Playgroud)

CSS:

.wrong {      
margin-top: 5px;       
padding: 5px;    
background-color:#F00;   
border: 2px solid #666;    
width:auto;
color: #000000;   
}
Run Code Online (Sandbox Code Playgroud)

我想要的是用PHP echo命令放入一点CSS.如果用户得到错误答案,则红色框应显示在中间"错误".

我已经尝试过了

echo <div class="wrong">"Wrong"</div>;
Run Code Online (Sandbox Code Playgroud)

但那没用.

Lek*_*eyn 7

PHP解释引号字符特殊,它标记字符串文字的开头或结尾.使用反斜杠转义引号或使用其他单引号:

<style>
.wrong {
    margin-top: 5px;
    padding: 5px;
    background-color: #F00;
    border: 2px solid #666;
    width: auto;
    color: #000000;
}
</style>
<?php
$submit = $_POST['submit'];
$answer = "8";
$input = strip_tags($_POST['input']);
if ($submit) {
    if ($input == $answer) {
        echo "Correct";
    } else {
        // note: escaped the quote character using a backslash
        echo "<div class=\"wrong\">wrong</div>";
        // alternative:
        //echo '<div class="wrong">wrong</div>';
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

另请参阅有关字符串类型PHP手册.