june_c21 Posted November 22, 2007 Share Posted November 22, 2007 when i write '001' in the form, the output appear '1' . how to make it become '001' ? Quote Link to comment https://forums.phpfreaks.com/topic/78349-interger/ Share on other sites More sharing options...
teng84 Posted November 22, 2007 Share Posted November 22, 2007 <?php echo '001';//001 echo intval('001');//1 echo (int)'001';//1 ?> or you mean when get it from your db? Quote Link to comment https://forums.phpfreaks.com/topic/78349-interger/#findComment-396430 Share on other sites More sharing options...
june_c21 Posted November 22, 2007 Author Share Posted November 22, 2007 $reg_id = 001; echo "$reg_id"; $reg_id++; i want it printed out as 001 insted of 1. Quote Link to comment https://forums.phpfreaks.com/topic/78349-interger/#findComment-396431 Share on other sites More sharing options...
Wes1890 Posted November 22, 2007 Share Posted November 22, 2007 idk, there probably is a function already.. but i made this: --- // preceding zero's function: Wes Foster // argument 1 - the int you choose // argument 2 -how many digits you would like the number to be (3 in this case) function precede($int,$digit) { if ( strlen($int) < $digit ) { $count = $digit - strlen($int); for ($i=0;$i<$count;$i++) { $final .= "0"; } $final .= $int; } return $final; } --- and use like: the $int is 59. $int = precede($int,3); now, $int will be "059" Quote Link to comment https://forums.phpfreaks.com/topic/78349-interger/#findComment-396432 Share on other sites More sharing options...
BenInBlack Posted November 22, 2007 Share Posted November 22, 2007 well you could use the built in function str_pad_left echo str_pad_left ( $reg_id , "0" , (3 - strlen($reg_id)) ); Quote Link to comment https://forums.phpfreaks.com/topic/78349-interger/#findComment-396445 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.