Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

smarty_modifier_size_format

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
myhan
Smarty n00b


Joined: 26 Sep 2003
Posts: 3

PostPosted: Fri Sep 26, 2003 1:31 am    Post subject: smarty_modifier_size_format Reply with quote

Format size like file size
[php:1:e90e24f7a4]
<?php

/*
* Smarty plugin
* -------------------------------------------------------------
* Type: modifier
* Name: size_format
* Purpose: format size
* Author: srni@wiscom.com.cn
*
* -------------------------------------------------------------
*/
function smarty_modifier_size_format($string, $sizestring=array("B", "K", "M"))
{
$bytes = (int)$string;
$type = $sizestring[0];
if ($bytes > 1024) {
$bytes /= 1024;
$type = $sizestring[1];
}
if ($bytes / 1024 > 1) {
$bytes /= 1024;
$type = $sizestring[2];
}
if ($bytes < 100) {
$bytes *= 100;
settype($bytes, 'integer');
$bytes /= 100;
} else {
settype($bytes, 'integer');
}
return $bytes . " " . $type;
}

/* vim: set expandtab: */


?>[/php:1:e90e24f7a4]
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP