微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么PHP回显在`background-image:ulr()`总是得到一个转义字符?

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

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

但完全没用!

谁能帮我? TAT

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

我不知道为什么style =“background-image:url(& quot; https://cdn.jsdelivr.net/example.jpg\u0026amp; quot;);”可以在我的browesr(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也可能对您有所帮助.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐