Jump to content

Archived

This topic is now archived and is closed to further replies.

anabelle

Three digit variable.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Use [url=http://www.php.net/sprintf]sprintf()[/url]

[code]<?php
echo sprintf("%03d",$id);
?>[/code]

Ken

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.