duanou9739
duanou9739
2016-08-25 16:50

在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 dongsheng4679 5年前

    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'>";
    
    点赞 评论 复制链接分享
  • dongyouzhui1969 dongyouzhui1969 5年前
    <?php if (isset($ioTitle)){
            echo "<div style='background-color:". $params->get('colorbgt').";' class=\"ioTitleBox\"><h3 class=\"ioTitle\">";
            echo $params->get("ioTitle"); echo "</h3></div>"; 
                        }
    

    Is this how you want it?

    You are echo-ing from inside an echo, you just need to concatenate that part into the existing echo statement.

    点赞 评论 复制链接分享

相关推荐