我正在尝试使用 PHP 回显一些内联 CSS:
echo '<div class="image" style="background:url("img/testimage.jpg");width:300px;height:232px;">';
echo '</div>';
但出于某种原因,这将返回:
<div class="image" testimage.jpg");width:300px;height:232px;"="" img="" style="background:url("></div>
这是在 WordPress 环境中,我是否做错了什么?
最佳答案
正确转义 url 声明中的引号:
echo '<div class="image" style="background:url(\'img/testimage.jpg\'); width:300px; height:232px;">';
// ^ ^
关于PHP echo 内联 CSS 背景 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26930740/