Results 1 to 3 of 3

Thread: modify number to string (ex: 1234 = 000-001-234)

  1. #1

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    modify number to string (ex: 1234 = 000-001-234)

    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?

  2. #2

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: modify number to string (ex: 1234 = 000-001-234)

    so far so good...now just for that hyphens

    Code:
    	$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.....

  3. #3

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: modify number to string (ex: 1234 = 000-001-234)

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width