PHP: how to print $page / $total_pages in each page without knowing $total_pages?

82 views Asked by At

Supposed we have a lengthy report to export, at each page's bottom we print

Page: $current_page / $total_pages

Problem is $total_pages is not easy to pre-count as more pages can be generated dynamically during file export.

What is your approach? Thank you!

1

There are 1 answers

0
Kittsil On BEST ANSWER

Obviously, you can't output something before you know it.

What you can do is store your output until you're done (using ob_start()), and then go through and clean up afterward.