在读取数据库的过程中常常遇到转换格式的问题,在网上也查了很多但都出错,自己修修改改的总算对了,贴出代码方便大家学习:
$rows['pubdate'] = date("Y-m-d",$rows['pubdate']);
//这样日期格式就由1426575060格式转换为2015-03-17格式了。
<?php echo strlen($rows['title'])>30? substr($rows['title'],0,30).'...':$rows['title'] ;?>
<!--这里限制字符长度,然后标题超出范围就会用省略号来表示了。-->
还有一种方法使用CSS来控制标题字数也是可行的:
.title{
width:200px;
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
}