这段代码有什么问题?HTML + PHP

跑痕

我有一个简单的函数,它有两个参数,一个用于图像的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>

我不知道这里出了什么问题,我正在使用引导程序

用户名

只需在函数中使用return语句而不是echo即可解决问题;-)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章