Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Create a table/css/div bar dynamically with php

SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
Watch

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.
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"));
?>
Create_bar(int percentage used..., string for text in the middle of the bar)

all comments/suggestions welcome...
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Cool, thanks for sharing!
 
0
Close
before i use i wanna look at this in demo, is there anywhere you have installed this so that i can view.
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back