PDA

Click to See Complete Forum and Search --> : modify number to string (ex: 1234 = 000-001-234)


StrangerInBeijing
Jan 23rd, 2008, 12:55 AM
Still a LOT I need to learn about PHP obviously.

I got a number (which is the id of a new record).

Now I want to build custom reference number (co_code-type_code-country-code-nnn-nnn-nnn)

So say i have anumber 1234 my reference number will look like SP-AG-CH-000-001-234)

So my question is how to make 1234, a string that will be 000-001-234?

StrangerInBeijing
Jan 23rd, 2008, 01:01 AM
so far so good...now just for that hyphens

$refnum = "SP-AG-".$country_code."-";
$num = rand(100, 100000000);
$num = str_pad($num, 9, "0", STR_PAD_LEFT);
//HOW TO ADD HYPHENS BETWEEN EACH 3RD NUM?
$refnum= $refnum.$num;
return $refnum;

hmmm....thousands seperator? lemme check that.....

StrangerInBeijing
Jan 23rd, 2008, 01:07 AM
nevermind..no need to use id from database

so just get 3 random numbers 3 times, pad them to the let with zero's, and the concacenate the lot together...

thanks for reading and wasing your time! :D