我的代码总是遇到这个问题:
<?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("https://cdn.jsdelivr.net/example.png"); 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%;">