【问题标题】:Check a string in Smarty在 Smarty 中检查字符串
【发布时间】:2014-06-24 06:50:06
【问题描述】:

我的 smarty 框架有问题,所以我需要验证图像名称是否以 'http' 开头: 我试试这段代码:

{foreach from=$video->result() item=v}

            {if substr($v->image,0,4) eq 'http'}
                <img src="{$v->image}" alt="">
            {else}
                <img src="{$IMG_URL}videos/images/{$v->date|date_format:'%Y'}/{$v->date|date_format:'%m'}/{$v->image}" alt="">
            {/if}

{/foreach}

请帮帮我..还有其他方式吗?

【问题讨论】:

    标签: smarty codeigniter-2 php-5.3 smarty3 smarty2


    【解决方案1】:

    这段代码应该可以正常工作。可能您的数据设置不正确。

    考虑以下测试代码:

    PHP 文件:

    class V {
    
        public $image = 'http://rwewreuiuiwre';
    }
    $smarty->assign('v', new V());
    

    模板文件:

    {if substr($v->image,0,4) eq 'http'}
    http
    {else}
    non http
    {/if}
    

    它工作正常。如果您将 $image 更改为 hxttp,您将收到 non http 消息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-08
      • 1970-01-01
      • 2017-12-02
      • 2012-02-15
      • 1970-01-01
      • 2013-01-09
      • 1970-01-01
      相关资源
      最近更新 更多