NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page [resolved] if & else function

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-30-2007, 05:50 AM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: Jul 2005
Posts: 1,492
newsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud of
 


AIDS/HIV Save a Life

if & else function


if(a.length == 1 ){
a = "000"+a;
}else if(a.length == 2){
a = "00"+a;
}else if(a.length == 3){
a = "0"+a;
}

How to rewrite the similiar function above for $p in php?
Can I replace "a" with "$p" ? It doesn't work at all. Any idea? Thanks
__________________
||||newsiness.com||||'""|""\__,_
| _[lol]___[lol]____ l ||__|__|)
|(@)(@)"""""""**|(@)(@)**|(@) 100% Free Online Flash games
newsiness is offline  
Old 08-30-2007, 06:22 AM   #2 (permalink)
NamePros Member
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 127
eagle12 will become famous soon enougheagle12 will become famous soon enough
 



PHP Code:
if(strlen($p)==1){
  
$p "000".$p;
} elseif(
strlen($p)==2) {
????: NamePros.com http://www.namepros.com/programming/368146-resolved-if-and-else-function.html
  
$p "00".$p;
????: NamePros.com http://www.namepros.com/showthread.php?t=368146
} elseif(
strlen($p)==3) {
  
$p "0"+$p;

I personally would build a function to handle it:

PHP Code:
function leading_zeros($num,$zeros){
    
$len strlen($num);
      for(
$i=$len;$i<$zeros;$i++){
           
$num "0".$num;
      }
      return 
$num;
}
 
$p leading_zeros($p,4); 
function leading_zeros($num,$zeros){
$len = strlen($num);
for($i=$len;$i<$zeros;$i++){
$num =. "0";
}
return $num;
}
eagle12 is offline  
Old 08-30-2007, 06:46 AM THREAD STARTER               #3 (permalink)
Senior Member
Join Date: Jul 2005
Posts: 1,492
newsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud ofnewsiness has much to be proud of
 


AIDS/HIV Save a Life
Originally Posted by eagle12
PHP Code:
if(strlen($p)==1){
  
$p "000".$p;
} elseif(
strlen($p)==2) {
  
$p "00".$p;
} elseif(
strlen($p)==3) {
????: NamePros.com http://www.namepros.com/showthread.php?t=368146
  
$p "0".$p;

I personally would build a function to handle it:
????: NamePros.com http://www.namepros.com/showthread.php?t=368146

PHP Code:
function leading_zeros($num,$zeros){
    
$len strlen($num);
      for(
$i=$len;$i<$zeros;$i++){
           
$num "0".$num;
      }
      return 
$num;
}
 
$p leading_zeros($p,4); 
function leading_zeros($num,$zeros){
$len = strlen($num);
for($i=$len;$i<$zeros;$i++){
$num =. "0";
}
return $num;
}
Thanks, it works!!! Rep added...

--resolved--
__________________
||||newsiness.com||||'""|""\__,_
| _[lol]___[lol]____ l ||__|__|)
|(@)(@)"""""""**|(@)(@)**|(@) 100% Free Online Flash games
newsiness is offline  
Old 08-30-2007, 07:51 AM   #4 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,556
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
Or better yet have a look at the str_pad function

http://www.php.net/str_pad
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:51 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger