anabelle Posted October 28, 2006 Share Posted October 28, 2006 Hi, im using a really simple script in www.gathacol.net/cenefa/ver.php?id=001 to generate the links in the arrows, im using [code]<? echo($id+1) ?>[/code]but it generates a single digit variable.. and i need always 3 digit so that the id works.How can i do to make the links to a three digit id? Link to comment https://forums.phpfreaks.com/topic/25418-three-digit-variable/ Share on other sites More sharing options...
kenrbnsn Posted October 28, 2006 Share Posted October 28, 2006 Use [url=http://www.php.net/sprintf]sprintf()[/url][code]<?phpecho sprintf("%03d",$id);?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/25418-three-digit-variable/#findComment-115981 Share on other sites More sharing options...
Psycho Posted October 28, 2006 Share Posted October 28, 2006 Assuming you want leading 0's:[code]$linkID = "00".($id+1);$linkID = substr($linkID,strlen($linkID)-3,3)echo $linkID;[/code]EDIT: Nevermind, I like his solution better. Link to comment https://forums.phpfreaks.com/topic/25418-three-digit-variable/#findComment-115984 Share on other sites More sharing options...
anabelle Posted October 28, 2006 Author Share Posted October 28, 2006 thanks ;) im using sprintfit works great! Link to comment https://forums.phpfreaks.com/topic/25418-three-digit-variable/#findComment-115991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.