duanou9739 2016-08-25 08:50
浏览 38
已采纳

在php echo中以css内联样式转义双引号

I am sorry if this is duplicated but I could not find an answer to this situation. I am trying to escape the double quotes from the inline style in the PHP code.

<?php if (isset($ioTitle)){
    echo "<div style='background-color: echo $params->get('colorbgt'); ;' class=\"ioTitleBox\"><h3 class=\"ioTitle\">";
    echo $params->get("ioTitle"); echo "</h3></div>"; 
}
  • 写回答

2条回答 默认 最新

  • dongsheng4679 2016-08-25 08:53
    关注

    You can't put echo inside a string and expect it to be executed. You need to use concatenation.

    echo "<div style='background-color: " . $params->get('colorbgt') . ";' class=\"ioTitleBox\"><h3 class=\"ioTitle\">";
    

    You don't need to escape anything in the style for this. Also, you can use single quotes around the classes, to avoid those escapes.

    echo "<div style='background-color: " . $params->get('colorbgt') . ";' class='ioTitleBox'><h3 class='ioTitle'>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?