3v4l.org

run code in 300+ PHP versions simultaneously
<?php function http_protocol() { return (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://'; } function http_host() { return $_SERVER['HTTP_HOST']; } function http_uri() { return parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); } function http_refactored_query_strings() { $queries = explode('&', $_SERVER['QUERY_STRING']); $refactoredQueries = []; foreach( $queries as $query ) { $refactoredQueries[] = filter_var(explode('=', $query)[1], FILTER_SANITIZE_STRING); } $queries = implode('/', $refactoredQueries); return $queries ?: ''; } function http_refactored_url() { return http_protocol() . http_host() . http_uri() . http_refactored_query_strings(); } echo http_refactored_url(); ?> <?php class Pagination { public $current_page; public $per_page; public $total_count; public $pages_articles; public function __construct($page=1, $per_page=20, $total_count=0) { $this->current_page = (int)$page; $this->per_page = (int)$per_page; $this->total_count = (int)$total_count; $this->pages_articles=array( '<div class="article-loop"><img src="http://i.imgur.com/CmU3tnl.jpg"></div>', '<div class="article-loop"><img src="http://i.imgur.com/TDdxS9H.png"></div>', '<div class="article-loop"><img src="http://i.imgur.com/39rpmwB.jpg"></div>', '<div class="article-loop"><img src="http://i.imgur.com/1lBZQ1B.png"></div>', '<div class="article-loop"><img src="https://i.imgur.com/Y5Ld4Qfh.jpg"></div>', '<div class="article-loop"><img src="http://i.imgur.com/wQVPRVp.png"></div>'); $this->total_count = sizeof($this->pages_articles); } public function offset() { return ($this->current_page - 1) * $this->per_page; } public function total_pages() { return ceil($this->total_count/$this->per_page); } public function previous_page() { return $this->current_page - 1; } public function next_page() { return $this->current_page + 1; } public function has_previous_page() { return $this->previous_page() >= 1 ? true : false; } public function has_next_page() { return $this->next_page() <= $this->total_pages() ? true : false; } } $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1; $per_page = 3; $pagination = new Pagination($page, $per_page, $total_count); ?> <html> <body> <div> <?php $i = $pagination->offset() ; $limit = $pagination->per_page; while($i<$pagination->total_count && $limit>0) { echo $pagination->pages_articles[$i]."<br>"; $i++; $limit--; } ?> </div> <ul> <?php if($pagination->has_previous_page()) { echo '<li style="display:inline"><a href="?page='.$pagination->previous_page().'">&laquo;</a></li>'; } else { echo '<li style="display:inline" class="disabled"><a href="#">&laquo;</a></li>'; } for($i=1; $i<=$pagination->total_pages(); $i++) { echo '<a href="?page='.$i.'"><li style="display:inline; margin-left:5px; margin-right:5px">'.$i.'</li></a>'; } if($pagination->has_next_page()) { echo '<li style="display:inline"><a href="?page='.$pagination->next_page().'">&raquo;</a></li>'; } else { echo '<li style="display:inline" class="disabled"><a href="#">&raquo;</a></li>'; } ?> </ul> </body> </html>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 28
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 50
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 53
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 72
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 53
Branch analysis from position: 63
Branch analysis from position: 53
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 28
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
Branch analysis from position: 39
Branch analysis from position: 39
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
filename:       /in/YE9Sb
function name:  (null)
number of ops:  75
compiled vars:  !0 = $page, !1 = $per_page, !2 = $pagination, !3 = $total_count, !4 = $i, !5 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_FCALL                                               'http_refactored_url'
          1        DO_FCALL                                      0  $6      
          2        ECHO                                                     $6
   72     3        FETCH_IS                                         ~7      '_GET'
          4        ISSET_ISEMPTY_DIM_OBJ                         1  ~8      ~7, 'page'
          5        BOOL_NOT                                         ~9      ~8
          6      > JMPZ                                                     ~9, ->12
          7    >   FETCH_R                      global              ~10     '_GET'
          8        FETCH_DIM_R                                      ~11     ~10, 'page'
          9        CAST                                          4  ~12     ~11
         10        QM_ASSIGN                                        ~13     ~12
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~13     1
         13    >   ASSIGN                                                   !0, ~13
   73    14        ASSIGN                                                   !1, 3
   74    15        NEW                                              $16     'Pagination'
         16        SEND_VAR_EX                                              !0
         17        SEND_VAR_EX                                              !1
         18        SEND_VAR_EX                                              !3
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !2, $16
   76    21        ECHO                                                     '%0A%3Chtml%3E%0A%3Cbody%3E%0A%3Cdiv%3E%0A'
   81    22        INIT_METHOD_CALL                                         !2, 'offset'
         23        DO_FCALL                                      0  $19     
         24        ASSIGN                                                   !4, $19
   82    25        FETCH_OBJ_R                                      ~21     !2, 'per_page'
         26        ASSIGN                                                   !5, ~21
   83    27      > JMP                                                      ->34
   84    28    >   FETCH_OBJ_R                                      ~23     !2, 'pages_articles'
         29        FETCH_DIM_R                                      ~24     ~23, !4
         30        CONCAT                                           ~25     ~24, '%3Cbr%3E'
         31        ECHO                                                     ~25
   85    32        PRE_INC                                                  !4
   86    33        PRE_DEC                                                  !5
   83    34    >   FETCH_OBJ_R                                      ~28     !2, 'total_count'
         35        IS_SMALLER                                       ~29     !4, ~28
         36      > JMPZ_EX                                          ~29     ~29, ->39
         37    >   IS_SMALLER                                       ~30     0, !5
         38        BOOL                                             ~29     ~30
         39    > > JMPNZ                                                    ~29, ->28
   89    40    >   ECHO                                                     '%3C%2Fdiv%3E%0A%3Cul%3E%0A'
   92    41        INIT_METHOD_CALL                                         !2, 'has_previous_page'
         42        DO_FCALL                                      0  $31     
         43      > JMPZ                                                     $31, ->50
   93    44    >   INIT_METHOD_CALL                                         !2, 'previous_page'
         45        DO_FCALL                                      0  $32     
         46        CONCAT                                           ~33     '%3Cli+style%3D%22display%3Ainline%22%3E%3Ca+href%3D%22%3Fpage%3D', $32
         47        CONCAT                                           ~34     ~33, '%22%3E%26laquo%3B%3C%2Fa%3E%3C%2Fli%3E'
         48        ECHO                                                     ~34
         49      > JMP                                                      ->51
   95    50    >   ECHO                                                     '%3Cli+style%3D%22display%3Ainline%22+class%3D%22disabled%22%3E%3Ca+href%3D%22%23%22%3E%26laquo%3B%3C%2Fa%3E%3C%2Fli%3E'
   97    51    >   ASSIGN                                                   !4, 1
         52      > JMP                                                      ->59
   98    53    >   CONCAT                                           ~36     '%3Ca+href%3D%22%3Fpage%3D', !4
         54        CONCAT                                           ~37     ~36, '%22%3E%3Cli+style%3D%22display%3Ainline%3B+margin-left%3A5px%3B+margin-right%3A5px%22%3E'
         55        CONCAT                                           ~38     ~37, !4
         56        CONCAT                                           ~39     ~38, '%3C%2Fli%3E%3C%2Fa%3E'
         57        ECHO                                                     ~39
   97    58        PRE_INC                                                  !4
         59    >   INIT_METHOD_CALL                                         !2, 'total_pages'
         60        DO_FCALL                                      0  $41     
         61        IS_SMALLER_OR_EQUAL                                      !4, $41
         62      > JMPNZ                                                    ~42, ->53
  100    63    >   INIT_METHOD_CALL                                         !2, 'has_next_page'
         64        DO_FCALL                                      0  $43     
         65      > JMPZ                                                     $43, ->72
  101    66    >   INIT_METHOD_CALL                                         !2, 'next_page'
         67        DO_FCALL                                      0  $44     
         68        CONCAT                                           ~45     '%3Cli+style%3D%22display%3Ainline%22%3E%3Ca+href%3D%22%3Fpage%3D', $44
         69        CONCAT                                           ~46     ~45, '%22%3E%26raquo%3B%3C%2Fa%3E%3C%2Fli%3E'
         70        ECHO                                                     ~46
         71      > JMP                                                      ->73
  103    72    >   ECHO                                                     '%3Cli+style%3D%22display%3Ainline%22+class%3D%22disabled%22%3E%3Ca+href%3D%22%23%22%3E%26raquo%3B%3C%2Fa%3E%3C%2Fli%3E'
  106    73    >   ECHO                                                     '%3C%2Ful%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
  108    74      > RETURN                                                   1

Function http_protocol:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  http_protocol
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   FETCH_IS                                         ~0      '_SERVER'
          1        ISSET_ISEMPTY_DIM_OBJ                         0          ~0, 'HTTPS'
          2      > JMPZ                                                     ~1, ->5
          3    >   QM_ASSIGN                                        ~2      'https'
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~2      'http'
          6    >   CONCAT                                           ~3      ~2, '%3A%2F%2F'
          7      > RETURN                                                   ~3
    4     8*     > RETURN                                                   null

End of function http_protocol

Function http_host:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  http_host
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   FETCH_R                      global              ~0      '_SERVER'
          1        FETCH_DIM_R                                      ~1      ~0, 'HTTP_HOST'
          2      > RETURN                                                   ~1
    8     3*     > RETURN                                                   null

End of function http_host

Function http_uri:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  http_uri
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_FCALL                                               'parse_url'
          1        FETCH_R                      global              ~0      '_SERVER'
          2        FETCH_DIM_R                                      ~1      ~0, 'REQUEST_URI'
          3        SEND_VAL                                                 ~1
          4        SEND_VAL                                                 5
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
   12     7*     > RETURN                                                   null

End of function http_uri

Function http_refactored_query_strings:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 22
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/YE9Sb
function name:  http_refactored_query_strings
number of ops:  32
compiled vars:  !0 = $queries, !1 = $refactoredQueries, !2 = $query
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'explode'
          1        SEND_VAL                                                 '%26'
          2        FETCH_R                      global              ~3      '_SERVER'
          3        FETCH_DIM_R                                      ~4      ~3, 'QUERY_STRING'
          4        SEND_VAL                                                 ~4
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !0, $5
   16     7        ASSIGN                                                   !1, <array>
   18     8      > FE_RESET_R                                       $8      !0, ->22
          9    > > FE_FETCH_R                                               $8, !2, ->22
   19    10    >   INIT_FCALL                                               'filter_var'
         11        INIT_FCALL                                               'explode'
         12        SEND_VAL                                                 '%3D'
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $10     
         15        FETCH_DIM_R                                      ~11     $10, 1
         16        SEND_VAL                                                 ~11
         17        SEND_VAL                                                 513
         18        DO_ICALL                                         $12     
         19        ASSIGN_DIM                                               !1
         20        OP_DATA                                                  $12
   18    21      > JMP                                                      ->9
         22    >   FE_FREE                                                  $8
   22    23        INIT_FCALL                                               'implode'
         24        SEND_VAL                                                 '%2F'
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                         $13     
         27        ASSIGN                                                   !0, $13
   23    28        JMP_SET                                          ~15     !0, ->30
         29        QM_ASSIGN                                        ~15     ''
         30      > RETURN                                                   ~15
   24    31*     > RETURN                                                   null

End of function http_refactored_query_strings

Function http_refactored_url:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  http_refactored_url
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'http_protocol'
          1        DO_FCALL                                      0  $0      
          2        INIT_FCALL                                               'http_host'
          3        DO_FCALL                                      0  $1      
          4        CONCAT                                           ~2      $0, $1
          5        INIT_FCALL                                               'http_uri'
          6        DO_FCALL                                      0  $3      
          7        CONCAT                                           ~4      ~2, $3
          8        INIT_FCALL                                               'http_refactored_query_strings'
          9        DO_FCALL                                      0  $5      
         10        CONCAT                                           ~6      ~4, $5
         11      > RETURN                                                   ~6
   28    12*     > RETURN                                                   null

End of function http_refactored_url

Class Pagination:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  __construct
number of ops:  19
compiled vars:  !0 = $page, !1 = $per_page, !2 = $total_count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV_INIT                                        !0      1
          1        RECV_INIT                                        !1      20
          2        RECV_INIT                                        !2      0
   40     3        CAST                                          4  ~4      !0
          4        ASSIGN_OBJ                                               'current_page'
          5        OP_DATA                                                  ~4
   41     6        CAST                                          4  ~6      !1
          7        ASSIGN_OBJ                                               'per_page'
          8        OP_DATA                                                  ~6
   42     9        CAST                                          4  ~8      !2
         10        ASSIGN_OBJ                                               'total_count'
         11        OP_DATA                                                  ~8
   43    12        ASSIGN_OBJ                                               'pages_articles'
   44    13        OP_DATA                                                  <array>
   50    14        FETCH_OBJ_R                                      ~11     'pages_articles'
         15        COUNT                                            ~12     ~11
         16        ASSIGN_OBJ                                               'total_count'
         17        OP_DATA                                                  ~12
   51    18      > RETURN                                                   null

End of function __construct

Function offset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  offset
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   FETCH_OBJ_R                                      ~0      'current_page'
          1        SUB                                              ~1      ~0, 1
          2        FETCH_OBJ_R                                      ~2      'per_page'
          3        MUL                                              ~3      ~1, ~2
          4      > RETURN                                                   ~3
   55     5*     > RETURN                                                   null

End of function offset

Function total_pages:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  total_pages
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   INIT_FCALL                                               'ceil'
          1        FETCH_OBJ_R                                      ~0      'total_count'
          2        FETCH_OBJ_R                                      ~1      'per_page'
          3        DIV                                              ~2      ~0, ~1
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6      > RETURN                                                   $3
   58     7*     > RETURN                                                   null

End of function total_pages

Function previous_page:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  previous_page
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   FETCH_OBJ_R                                      ~0      'current_page'
          1        SUB                                              ~1      ~0, 1
          2      > RETURN                                                   ~1
   61     3*     > RETURN                                                   null

End of function previous_page

Function next_page:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  next_page
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   FETCH_OBJ_R                                      ~0      'current_page'
          1        ADD                                              ~1      ~0, 1
          2      > RETURN                                                   ~1
   64     3*     > RETURN                                                   null

End of function next_page

Function has_previous_page:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  has_previous_page
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   INIT_METHOD_CALL                                         'previous_page'
          1        DO_FCALL                                      0  $0      
          2        IS_SMALLER_OR_EQUAL                                      1, $0
          3      > JMPZ                                                     ~1, ->6
          4    >   QM_ASSIGN                                        ~2      <true>
          5      > JMP                                                      ->7
          6    >   QM_ASSIGN                                        ~2      <false>
          7    > > RETURN                                                   ~2
   67     8*     > RETURN                                                   null

End of function has_previous_page

Function has_next_page:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YE9Sb
function name:  has_next_page
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   INIT_METHOD_CALL                                         'next_page'
          1        DO_FCALL                                      0  $0      
          2        INIT_METHOD_CALL                                         'total_pages'
          3        DO_FCALL                                      0  $1      
          4        IS_SMALLER_OR_EQUAL                                      $0, $1
          5      > JMPZ                                                     ~2, ->8
          6    >   QM_ASSIGN                                        ~3      <true>
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~3      <false>
          9    > > RETURN                                                   ~3
   70    10*     > RETURN                                                   null

End of function has_next_page

End of class Pagination.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.99 ms | 1423 KiB | 28 Q