【问题标题】:What is the correct way to apply css on php echo?在 php echo 上应用 css 的正确方法是什么?
【发布时间】:2013-01-19 22:05:12
【问题描述】:

如何在下面的回声上应用 css?在为 UTF 编码添加标头之前,我让它工作了,但现在它也回显了 css,所以我的回显结果是:<p align='center'>Good!!!</p>

<?php 
header('Content-type: text/plain; charset=utf-8');

$answer = $_POST['1'];  
if ($answer == "YES") {          
    echo 'Good!!!';      
}
else {
    echo 'Try Again!';
} 
?>

更正:

<?php 
    header('Content-type: text/html; charset=utf-8');

    $answer = $_POST['1'];  
    if ($answer == "YES") {          
        echo "<p align='center'>Good!!!</p>";        
    }
    else {
        echo "<p align='center'>Try Again!</p>";  
    } 
    ?>

【问题讨论】:

  • 你知道Content-type: text/plain 是做什么的吗?即使您不这样做,如果它在此之前有效,则意味着此更改破坏了它。所以谷歌并找出原因。
  • 此代码从未回显&lt;p align...
  • 为什么将标题设置为 text/plain?没有多大意义,但至少改成text/html
  • CSS?你的意思是HTML?我很困惑...
  • 不知道 text/plain 会禁用 html 是的。没有必要像疯了一样投反对票。

标签: php css


【解决方案1】:

您正在发送标头:

Content-type: text/plain;

它告诉浏览器传入的数据是纯文本,而不是 html,因此返回数据中的任何标记都将被忽略。

【讨论】:

    猜你喜欢
    • 2018-04-28
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多