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>
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key "HTTP_HOST" in /in/YE9Sb on line 7 Warning: Undefined array key "REQUEST_URI" in /in/YE9Sb on line 11 Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /in/YE9Sb on line 11 Warning: Undefined array key "QUERY_STRING" in /in/YE9Sb on line 15 Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /in/YE9Sb on line 15 Warning: Undefined array key 1 in /in/YE9Sb on line 19 Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /in/YE9Sb on line 19 http:// Warning: Undefined variable $total_count in /in/YE9Sb on line 74 <html> <body> <div> <div class="article-loop"><img src="http://i.imgur.com/CmU3tnl.jpg"></div><br><div class="article-loop"><img src="http://i.imgur.com/TDdxS9H.png"></div><br><div class="article-loop"><img src="http://i.imgur.com/39rpmwB.jpg"></div><br></div> <ul> <li style="display:inline" class="disabled"><a href="#">&laquo;</a></li><a href="?page=1"><li style="display:inline; margin-left:5px; margin-right:5px">1</li></a><a href="?page=2"><li style="display:inline; margin-left:5px; margin-right:5px">2</li></a><li style="display:inline"><a href="?page=2">&raquo;</a></li></ul> </body> </html>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key "HTTP_HOST" in /in/YE9Sb on line 7 Warning: Undefined array key "REQUEST_URI" in /in/YE9Sb on line 11 Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /in/YE9Sb on line 11 Warning: Undefined array key "QUERY_STRING" in /in/YE9Sb on line 15 Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /in/YE9Sb on line 15 Warning: Undefined array key 1 in /in/YE9Sb on line 19 Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /in/YE9Sb on line 19 http:// Warning: Undefined variable $total_count in /in/YE9Sb on line 74 <html> <body> <div> <div class="article-loop"><img src="http://i.imgur.com/CmU3tnl.jpg"></div><br><div class="article-loop"><img src="http://i.imgur.com/TDdxS9H.png"></div><br><div class="article-loop"><img src="http://i.imgur.com/39rpmwB.jpg"></div><br></div> <ul> <li style="display:inline" class="disabled"><a href="#">&laquo;</a></li><a href="?page=1"><li style="display:inline; margin-left:5px; margin-right:5px">1</li></a><a href="?page=2"><li style="display:inline; margin-left:5px; margin-right:5px">2</li></a><li style="display:inline"><a href="?page=2">&raquo;</a></li></ul> </body> </html>
Output for 8.0.0 - 8.0.30
Warning: Undefined array key "HTTP_HOST" in /in/YE9Sb on line 7 Warning: Undefined array key "REQUEST_URI" in /in/YE9Sb on line 11 Warning: Undefined array key "QUERY_STRING" in /in/YE9Sb on line 15 Warning: Undefined array key 1 in /in/YE9Sb on line 19 http:// Warning: Undefined variable $total_count in /in/YE9Sb on line 74 <html> <body> <div> <div class="article-loop"><img src="http://i.imgur.com/CmU3tnl.jpg"></div><br><div class="article-loop"><img src="http://i.imgur.com/TDdxS9H.png"></div><br><div class="article-loop"><img src="http://i.imgur.com/39rpmwB.jpg"></div><br></div> <ul> <li style="display:inline" class="disabled"><a href="#">&laquo;</a></li><a href="?page=1"><li style="display:inline; margin-left:5px; margin-right:5px">1</li></a><a href="?page=2"><li style="display:inline; margin-left:5px; margin-right:5px">2</li></a><li style="display:inline"><a href="?page=2">&raquo;</a></li></ul> </body> </html>
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Notice: Undefined index: HTTP_HOST in /in/YE9Sb on line 7 Notice: Undefined index: REQUEST_URI in /in/YE9Sb on line 11 Notice: Undefined index: QUERY_STRING in /in/YE9Sb on line 15 Notice: Undefined offset: 1 in /in/YE9Sb on line 19 http:// Notice: Undefined variable: total_count in /in/YE9Sb on line 74 <html> <body> <div> <div class="article-loop"><img src="http://i.imgur.com/CmU3tnl.jpg"></div><br><div class="article-loop"><img src="http://i.imgur.com/TDdxS9H.png"></div><br><div class="article-loop"><img src="http://i.imgur.com/39rpmwB.jpg"></div><br></div> <ul> <li style="display:inline" class="disabled"><a href="#">&laquo;</a></li><a href="?page=1"><li style="display:inline; margin-left:5px; margin-right:5px">1</li></a><a href="?page=2"><li style="display:inline; margin-left:5px; margin-right:5px">2</li></a><li style="display:inline"><a href="?page=2">&raquo;</a></li></ul> </body> </html>
Output for 7.3.32 - 7.3.33, 7.4.26
http:// <html> <body> <div> <div class="article-loop"><img src="http://i.imgur.com/CmU3tnl.jpg"></div><br><div class="article-loop"><img src="http://i.imgur.com/TDdxS9H.png"></div><br><div class="article-loop"><img src="http://i.imgur.com/39rpmwB.jpg"></div><br></div> <ul> <li style="display:inline" class="disabled"><a href="#">&laquo;</a></li><a href="?page=1"><li style="display:inline; margin-left:5px; margin-right:5px">1</li></a><a href="?page=2"><li style="display:inline; margin-left:5px; margin-right:5px">2</li></a><li style="display:inline"><a href="?page=2">&raquo;</a></li></ul> </body> </html>

preferences:
176.09 ms | 403 KiB | 173 Q