[英]MySQL / PHP background image URL 2
I have a little problem with a php/sql backgroung-image. 我对php / sql backgroung-image有一点问题。 My code is
我的代码是
while($row = mysql_fetch_array($result)){
echo
'<div>',
'<div>',
'<a href="#">',
'<div class="coupimage" style="background-image: url("'.$row['img_5'].'");"></div></a>',
'<br />',
'<h3>'.$row['var1'].'</h3>', '<br />',
$row['var2'],', ',
$row['var3'],'<br />',
$row['var4'],', ',
$row['var5'], '<br />',
'</div>',
'</div>';
}
It work good for each "var" but background-image don't work. 它对每个“ var”都有效,但背景图像不起作用。
echo $row['img_5'];
print correct link and if I use 打印正确的链接,如果我使用
'<img src="'.$row['img_5'].'">'
work great too but in style class it return image link without "/" and it don't work. 效果也很好,但是在样式类中,它返回不带“ /”的图像链接,并且不起作用。
ex http://www.example.org/image.jpg -> http: www.example.org image.jpg 例如http://www.example.org/image.jpg- > http:www.example.org image.jpg
What I have to do? 我该怎么办?
Replace space to "/" 将空格替换为“ /”
// $str == $row['img_5']
// It will work if we got an space
$str = "http: www.example.org image.jpg";
$arr = explode(" ", $str);
$url = $arr[0]."/".$arr[1];
In ur case : 在您的情况下:
while($row = mysql_fetch_array($result)){
$arr = explode(" ", $row['img_5']);
$url = $arr[0]."/".$arr[1];
echo
'<div>',
'<div>',
'<a href="#">',
'<div class="coupimage" style="background-image: url("'.$url.'");"></div></a>',
'<br />',
'<h3>'.$row['var1'].'</h3>', '<br />',
$row['var2'],', ',
$row['var3'],'<br />',
$row['var4'],', ',
$row['var5'], '<br />',
'</div>',
'</div>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.