我有一个简单的函数,它有两个参数,一个是图片 url,另一个是图片的属性
function image_found($url,$attributes)
{
if(@getimagesize($url))
{
echo '<img src="'.$url.'" '.$attributes.'/>';
}
else
{
echo '<img src="'.base_url().'/site_images/image_not_found.svg" '.$attributes.'/>';
}
}
现在我要做的是创建一个可点击的图像,如果找到图像,现在这是 html 代码
echo '<div class="panel-body">';
echo '<div class="col-md-12 col-lg-12 col-sm-12 text-center">';
$url = base_url().'product_images/'.$result->product_image.'.'.$result->image_type;
$attributes = 'height="200px" width="100%"';
echo '<a href="product.com/full/url">'.image_found($url,$attributes).'</a>';
echo '</div>';
echo '</div>';
这是我得到的输出
<div class="panel-body">
<div class="col-md-12 col-lg-12 col-sm-12 text-center">
<img src="http://localhost/nsc/product_images/7908076366784972032090.jpg" height="200px" width="100%"/>
<a href="#"></a>
</div>
</div>
我不知道这里有什么问题,我正在使用 bootstrap
最佳答案
只需在您的函数中使用 return 语句而不是 echo,您的问题就应该得到解决 ;-)
关于php - 这段代码有什么问题? HTML + PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29823790/