为什么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也可能对您有所帮助.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...