0

I'm tying create a reference generator in PHP, and i need format String.

i tried this code but don't work

function refAll($db, $contest, $ano){
$newkey = getlastid($db)+1;
return sprintf("%s%d%1$05d",$contest, $ano, $newkey);}

the goal is the output sting formatted like this ABC201500000, where ABC2015 is fixed and the 00000 is always the value in $newkey but with 5 digits

in my code

$newkey = 1

$contest = ABC

$ano = 2015

and the output is always ABC201500000

4
  • Your problem is probably in getlastid() since that is what generates the value for $newKey which is not working. Commented Sep 25, 2014 at 16:48
  • the value of $newkey is correct, and if i forced a value sprintf("%s%d%1$05d",$contest, $ano, 1234), give me the same result Commented Sep 25, 2014 at 16:53
  • $05d? Shouldn't that be %05d? $05 means nothing to sprintf Commented Sep 25, 2014 at 16:54
  • "the goal is the output sting formatted like this ABC201500000" / "and the output is always ABC201500000". So it's working then? Commented Sep 25, 2014 at 16:57

1 Answer 1

2

Try this:

sprintf("%s%d%05d",$contest, $ano, $newkey)    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.