Need a variable like fpdf's AliasNbPages

I know what I need but I’m not sure what it’s called…

What I need is similar to the AliasNbPages method on in fpdf (go to FPDF , click Manual, then click AliasNbPages).

AliasNbPages substitues an alias with a value AFTER a script is finished running.

How can I do this in PHP? Since I’m not sure what I’m looking for… does this make sense?

Let me explain what I’m trying to do…

I am building a PDF in a custom way where I have to control the page numbers myself. Each page of each PDF has a “Page 1 of n” line of text.

Whether there is 1 page or 20, I won’t know until the loop that builds the PDF is done. So when the loop is done I have to go back and fill in n.

Is there anything in PHP where I can delcare a sortof placeholder variable and fill it in later on in the script?