swiss73 Posted November 24, 2006 Share Posted November 24, 2006 Hi. I want to echo a random number 01 to 29. I can't rename the files as left-1.jpg to left-29.jpg. they have to stay as left-01.jpg to left-29.jpgwho can help with this? I searched but did not find how to format numbers in php Link to comment https://forums.phpfreaks.com/topic/28347-rand0129-not-129-how/ Share on other sites More sharing options...
taith Posted November 24, 2006 Share Posted November 24, 2006 [code]$i = rand(1,29);if(strlen($i)==1) $i = '0'.$i;[/code] Link to comment https://forums.phpfreaks.com/topic/28347-rand0129-not-129-how/#findComment-129657 Share on other sites More sharing options...
swiss73 Posted November 24, 2006 Author Share Posted November 24, 2006 thank you. that is an intelligent answer indeed. :) Link to comment https://forums.phpfreaks.com/topic/28347-rand0129-not-129-how/#findComment-129660 Share on other sites More sharing options...
taith Posted November 24, 2006 Share Posted November 24, 2006 your quite welcome :-D Link to comment https://forums.phpfreaks.com/topic/28347-rand0129-not-129-how/#findComment-129661 Share on other sites More sharing options...
mansuang Posted November 24, 2006 Share Posted November 24, 2006 [code=php:0]$i = sprintf("%02d",rand(1,29));[/code]here is another choice. Link to comment https://forums.phpfreaks.com/topic/28347-rand0129-not-129-how/#findComment-129662 Share on other sites More sharing options...
swiss73 Posted November 24, 2006 Author Share Posted November 24, 2006 [quote author=mansuang link=topic=116171.msg473170#msg473170 date=1164390648][code=php:0]$i = sprintf("%02d",rand(1,29));[/code]here is another choice.[/quote]thank you very much I will try that too. Link to comment https://forums.phpfreaks.com/topic/28347-rand0129-not-129-how/#findComment-129671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.