axilant
Account Closed
- Impact
- 28
Alright with my new project, i needed to use a bar to show a user how much space he/she is using... and i thought i would share this great function.
Create_bar(int percentage used..., string for text in the middle of the bar)
all comments/suggestions welcome...
PHP:
<?
function create_bar($width, $show_text = '')
{
$bar = '';
if ( strstr($width, '%') )
{
$width = intval(str_replace('%', '', $width));
if($width > 0)
{
$width = ( intval($width) <= 100 ) ? $width . '%' : '100%';
}
}
if($width > 0)
{
$bar = "<table width=\"100\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"10\">\n";
$bar .= "\t<tr>\n\t\t<td width=\"100%\" align=\"left\" style=\"border: 1px solid #AAAAAA; background-color: #CECECE;\" nowrap=\"nowrap\">";
$bar .= "\n\t\t\t<div style=\"background-color: #26E81C; margin: 2px; height: 10px; width: {$width}px;\">";
if ($show_text != "")
{
$bar .= "\n\t\t\t\t<span style=\"font-size: 10px;\">$show_text</span>";
}
$bar .= "\n\t\t\t</div>\n\t\t</td>\n\t</tr>\n</table>";
}
return $bar;
}
print(create_bar("10","10/100"));
?>
all comments/suggestions welcome...