grunshaw Posted August 8, 2009 Share Posted August 8, 2009 For those of you that have seen and helped me with my other post about formatting and splitting a variable string, you will know i'm working on a mobility system for the visually impaired. One of the requirements is to have a Map ID (or Route ID) that should be 3 digits and be between 001 and 099. Thats great - but I cant seem to generate one. Here is what I have done, if someone can correct me, that would be greate $rid=rand(1,999); if($rid < 100){ $int="0"; $int.="$rid"; } if($rid < 10){ $int="00"; $int.="$rid"; } It seems to work sometimes, but when I call $int it comes up blank 95% of the time. All the best James. PS > Thanks for the removeal of teh CAPATCHAS who ever did it - its much appriciated. Link to comment https://forums.phpfreaks.com/topic/169351-solved-generate-3-digit-number-with-leading-0s/ Share on other sites More sharing options...
Mardoxx Posted August 8, 2009 Share Posted August 8, 2009 str_pad((int)$rid,3,"0",STR_PAD_LEFT); //edit, i was right the first time so basically $rid=rand(1,999); $rid=str_pad((int)$rid,3,"0",STR_PAD_LEFT); Link to comment https://forums.phpfreaks.com/topic/169351-solved-generate-3-digit-number-with-leading-0s/#findComment-893602 Share on other sites More sharing options...
grunshaw Posted August 8, 2009 Author Share Posted August 8, 2009 Brilliant! All works well with that one now! I feel like such a Noob! Link to comment https://forums.phpfreaks.com/topic/169351-solved-generate-3-digit-number-with-leading-0s/#findComment-893603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.