$count=count($rr);//图片个数
$picpath='';
for($i=0;$i<$count;$i++)
{
$fr=explode($fexp,$rr[$i]);
$smallpic=$fr[0]; //小图
$bigpic=$fr[1]; //大图
if(empty($bigpic))
{
$bigpic=$smallpic;
}
$width=$public_r[spicwidth]?" width='".$public_r[spicwidth]."'":'';//宽度
$height=$public_r[spicheight]?" height='".$public_r[spicheight]."'":'';//高度
$picpath.="<a href='".$public_r[newsurl].$bigpic."' target='imgview' rel='nofollow'><img src='".$smallpic."'".$width.$height." /></a>";
$picpath.='</li>';
}
$ulpre='<div class="thumbox"><ul class="thumblist ovf">';
$ulsuf="</ul></div>";
$value=$ulpre.$picpath.$ulsuf;
return $value;
现在是每个图片都是由<li>包裹着,想把它改成<li>包裹图片数量不大於5,比如6张图片就是两个li:<li>...</li><li><img alt=6></li>因为自己能力有限,不知道是不是求count除以5的余数再加一个循环呢? 感觉好像很复杂,不知道怎么写,有空的写一下代码,没空的麻烦指点一下关键的地方,谢谢!
$picpath='';
for($i=0;$i<$count;$i++)
{
$fr=explode($fexp,$rr[$i]);
$smallpic=$fr[0]; //小图
$bigpic=$fr[1]; //大图
if(empty($bigpic))
{
$bigpic=$smallpic;
}
$width=$public_r[spicwidth]?" width='".$public_r[spicwidth]."'":'';//宽度
$height=$public_r[spicheight]?" height='".$public_r[spicheight]."'":'';//高度
$picpath.="<a href='".$public_r[newsurl].$bigpic."' target='imgview' rel='nofollow'><img src='".$smallpic."'".$width.$height." /></a>";
$picpath.='</li>';
}
$ulpre='<div class="thumbox"><ul class="thumblist ovf">';
$ulsuf="</ul></div>";
$value=$ulpre.$picpath.$ulsuf;
return $value;
现在是每个图片都是由<li>包裹着,想把它改成<li>包裹图片数量不大於5,比如6张图片就是两个li:<li>...</li><li><img alt=6></li>因为自己能力有限,不知道是不是求count除以5的余数再加一个循环呢? 感觉好像很复杂,不知道怎么写,有空的写一下代码,没空的麻烦指点一下关键的地方,谢谢!
解决方案 »
- 遍历对象 并获取对象值
- PHP怎么执行SQL语句查询TXT中的内容?
- php网站 上一页 下一页如何调用
- 向大家请教一个问题.....用PHP或HTML有或CSS来告诉我怎么弄都可以
- PHP获取XML格式的URL
- 一个获取 土豆网 toodou.com 视频真实地址的PHP源代码!
- php 三表查询怎么会错误的呢
- 有谁可以将以下 perl 代码翻译为 PHP
- 求助,如何将foxpro里的数据导入到mysql里去?
- charset=gb2312错在哪儿?
- Warning:preg_match() [function.preg-match]:Compilation failed:nothing to repeat
- PHP中添加SP增值业务
<ul class="thumblist ovf">
<li>
<?php
$output = ''; for($i=0;$i<$count;$i++)
{
if( ($count % 5) === 1 ) // 已经循环第6次的话
$output .= </li><li> // 包含在新<li>里
$output .= '图片';
}
?>
</li>
</ul>
</div>
$c = 0; //计数器
$str = '';for ($i = 0; $i < 12; $i ++) {
$c = $c % 5;
if ($c == 0) $str .= '<li>';
$str .= '<img />';
++ $c;
if ($c == 5) $str .= '</li>';
//$c ++;
}
if ($c != 5) $str .= '</li>';echo htmlspecialchars($str);
如果有12个图片,是不是($i % 5) === 1||($i % 5) === 2如果有18个图片,那就($i % 5) === 1||($i % 5) === 2||($i % 5) === 3图片越多岂不是要写更多?
<li>
<?php
$output = '';
$count = 18;
for($i=1; $i<=$count; $i++)
{
if( ($i % 5) === 1 && $i !== 1) // 已经循环第6次的话
$output .= "\n </li>\n <li>\n"; // 包含在新<li>里
$output .= "<img id={$i} />";
}
echo $output;
?>
</li>
output:
<li>
<img id=1 /><img id=2 /><img id=3 /><img id=4 /><img id=5 />
</li>
<li>
<img id=6 /><img id=7 /><img id=8 /><img id=9 /><img id=10 />
</li>
<li>
<img id=11 /><img id=12 /><img id=13 /><img id=14 /><img id=15 />
</li>
<li>
<img id=16 /><img id=17 /><img id=18 />
</li>