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

标签 php html twitter-bootstrap

我有一个简单的函数,它有两个参数,一个是图片 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/

相关文章:

php - cURL 无法连接到主机,但它连接到我的域地址

php - 将 TINYINT(1) 转换为字符串

php - 在多个数组中搜索

javascript - 等待发出 AngularJS HTTP 请求

javascript - 从 div 元素中检索具有特定类的所有子元素标签

css - Twitter Bootstrap 2 流体布局应适合屏幕(+ 可滚动区域)

html - 在导航堆叠元素旁边放置字形图标

php - Yii2 GridView 排序

javascript - 将元素从附加列表传递到另一个页面

html - Bootstrap 4 导航栏在移动设备上重叠