3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $currentpageid = $nmstart = 23; $nrtotal = 23; $nrposts = 1; $pages = ''; $ssPagingStartCount = 3; $ssPagingCurrentCount = 3; $ssPagingEndCount = 2; $totalpages = ceil($nrtotal / $nrposts); if ($totalpages > 1 ){ for ($x = 0; $x < $totalpages; ++$x) { $inc = $x * $nrposts; $display = $x + 1; if($inc != $nmstart) { $pages .= "\n<a class=\"nl_page\" href='" . "nmstart=$inc'>&nbsp;".$display."&nbsp;</a>"; /* < [1] 2 3 ... 22 23 > < 1 [2] 3 ... 22 23 > < 1 2 [3] 4 ... 22 23 > < 1 2 3 [4] 5 ... 22 23 > < 1 2 ... 4 [5] 6 ... 22 23 > < 1 2 ... 5 [6] 7 ... 22 23 > ... < 1 2 ... 18 [19] 20 ... 22 23 > */ } else { $pages .= "\n<span class=\"nl_page nl_page__currentpage\">&nbsp;".$display."&nbsp;</span>"; } } } var_dump($pages); ?>
based on vS3fp
Output for 4.3.0 - 7.2.0
string(1269) " <a class="nl_page" href='nmstart=0'>&nbsp;1&nbsp;</a> <a class="nl_page" href='nmstart=1'>&nbsp;2&nbsp;</a> <a class="nl_page" href='nmstart=2'>&nbsp;3&nbsp;</a> <a class="nl_page" href='nmstart=3'>&nbsp;4&nbsp;</a> <a class="nl_page" href='nmstart=4'>&nbsp;5&nbsp;</a> <a class="nl_page" href='nmstart=5'>&nbsp;6&nbsp;</a> <a class="nl_page" href='nmstart=6'>&nbsp;7&nbsp;</a> <a class="nl_page" href='nmstart=7'>&nbsp;8&nbsp;</a> <a class="nl_page" href='nmstart=8'>&nbsp;9&nbsp;</a> <a class="nl_page" href='nmstart=9'>&nbsp;10&nbsp;</a> <a class="nl_page" href='nmstart=10'>&nbsp;11&nbsp;</a> <a class="nl_page" href='nmstart=11'>&nbsp;12&nbsp;</a> <a class="nl_page" href='nmstart=12'>&nbsp;13&nbsp;</a> <a class="nl_page" href='nmstart=13'>&nbsp;14&nbsp;</a> <a class="nl_page" href='nmstart=14'>&nbsp;15&nbsp;</a> <a class="nl_page" href='nmstart=15'>&nbsp;16&nbsp;</a> <a class="nl_page" href='nmstart=16'>&nbsp;17&nbsp;</a> <a class="nl_page" href='nmstart=17'>&nbsp;18&nbsp;</a> <a class="nl_page" href='nmstart=18'>&nbsp;19&nbsp;</a> <a class="nl_page" href='nmstart=19'>&nbsp;20&nbsp;</a> <a class="nl_page" href='nmstart=20'>&nbsp;21&nbsp;</a> <a class="nl_page" href='nmstart=21'>&nbsp;22&nbsp;</a> <a class="nl_page" href='nmstart=22'>&nbsp;23&nbsp;</a>"