当前位置: 动力学知识库 > 问答 > 编程问答 >

html - Escape the double quotes in css inline style in php echo

问题描述:

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>";

}

网友答案:

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'>";
网友答案:
<?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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: