但无论我做什么,html 总是显-6ren">
gpt4 book ai didi

php - 为什么 `background-image:ulr()` 中的 PHP echo 总是得到一个转义字符?

转载 作者:搜寻专家 更新时间:2023-10-31 20:58:25 24 4
gpt4 key购买 nike

我的代码总是遇到这个问题:

<?php
$imgurl = "https://cdn.jsdelivr.net/example.png";
$get_style = 'background-image: url(\''.$imgurl.'\'); ';
?>
<figure id="centerbg" class="centerbg" style="<?php echo $get_style; ?>background-position: center center;background-attachment: inherit;">

但无论我做什么,html 总是显示:

<figure id="centerbg" class="centerbg" style="background-image: url(&quot;https://cdn.jsdelivr.net/example.png&quot;); background-position: center center; background-attachment: inherit;">

我也试过:

<figure id="centerbg" class="centerbg" style="background-image: url(<?php echo $imgurl ?>);background-position: center center;background-attachment: inherit;">

但是一点用都没有!

谁能帮帮我?时间

感谢您的帮助,但似乎我和您的代码在这个文件中都能正常工作:https://api.mashiro.top/cover/test.php , 但始终在我的生产站点中获取转义字符(与封面图像相同的 HTML id):https://2heng.xin/ , 真的很奇怪,我网站的其他部分是否有可能出错?

我不知道为什么 style="background-image: url("https://cdn.jsdelivr.net/example.jpg");" 可以在我的浏览器中显示图片(Chrome 和 Firefox),但这不是一个很好的表达方式吗?

最佳答案

您也可以只删除 $get_style 变量上的单引号。

<?php
$imgurl = "https://cdn.jsdelivr.net/example.png";
$get_style = 'background-image: url('.$imgurl.');';
?>
<figure id="centerbg" class="centerbg" style="<?php echo $get_style; ?>background-position: center center;background-attachment: inherit;height:100%;">

而且您的网站似乎正在使用 WordPress,所以这 link也可能对您有所帮助。

关于php - 为什么 `background-image:ulr()` 中的 PHP echo 总是得到一个转义字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50099707/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com