search
Homephp教程php手册volist 标签 第一个和最后一个判断

处理头尾是经常的事
找到 ThinkPHP\Library\Think\Template\TagLib\Cx.class.php
找到 _volist 方法 替换成下面代码(本人写的代码比较粗,看官们勿笑)public function _volist($tag,$content) {<br>         $name  =    $tag['name'];<br>         $id    =    $tag['id'];<br>         $empty =    isset($tag['empty'])?$tag['empty']:'';<br>         $key   =    !empty($tag['key'])?$tag['key']:'i';<br>         $mod   =    isset($tag['mod'])?$tag['mod']:'2';<br>         // 允许使用函数设定数据集 <volist>{$vo.name}</volist><br>         $parseStr   =  '<?php &#039;;<br />         // $parseStr   =  '$length=count('.$name.') ';<br>         if(0===strpos($name,':')) {<br>             $parseStr   .= '$_result='.substr($name,1).';';<br>             $name   = '$_result';<br>         }else{<br>             $name   = $this->autoBuildVar($name);<br>         }<br>         $parseStr  .=  'if(is_array('.$name.')): $'.$key.' = 0;';<br>         if(isset($tag['length']) && '' !=$tag['length'] ) {<br>             $parseStr  .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].','.$tag['length'].',true);';<br>         }elseif(isset($tag['offset'])  && '' !=$tag['offset']){<br>             $parseStr  .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].',null,true);';<br>         }else{<br>             $parseStr .= ' $__LIST__ = '.$name.';';<br>         }<br>         $parseStr .= '$is_first=false;$is_last=false;$_key=0;$length=count($__LIST__);';<br>         $parseStr .= 'if( count($__LIST__)==0 ) : echo "'.$empty.'" ;';<br>         $parseStr .= 'else: ';<br>         $parseStr .= 'foreach($__LIST__ as $key=>$'.$id.'): ';<br>         $parseStr .= 'if($_key==0) : $is_first=true; else :$is_first=false;endif;';<br>         $parseStr .= 'if($_key==($length-1)) :$is_last=true; else :$is_last=false;endif;';<br>         $parseStr .= '$_key++;';<br>         $parseStr .= '$mod = ($'.$key.' % '.$mod.' );';<br>         $parseStr .= '++$'.$key.';?>';<br>         $parseStr .= $this->tpl->parse($content);<br>         $parseStr .= '<?php endforeach; endif; else: echo "&#039;.$empty.&#039;" ;endif; ?>';<br> <br>         if(!empty($parseStr)) {<br>             return $parseStr;<br>         }<br>         return ;<br>     }模板中<volist><br>             <li>{$vo.value}<br>             <eq>______这是第一条</eq><br>             <eq>______这是最后一条</eq><br>             </li> <br> </volist>如有错误,请告知 398235105@qq.com

AD:真正免费,域名+虚机+企业邮箱=0元

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools