3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class content { public function get_header() { $returned = array(); $confdir = ($_SERVER['DOCUMENT_ROOT']. '\site\config.xml'); $xml= simplexml_load_file($confdir); $title = ($xml->site->title); $hmenu = ($xml->content->nav); $ntitle = (string)$title; $nhmenu = (string)$hmenu; $returned[] = "<div class = 'header'>"; //header start $returned[] = '<div class = "title"><h1>'. $ntitle. '</h1></div>'; $returned[] = '<div class = "login">'; $returned[] = '<form>'; $returned[] = '<p>Username: <input type = "text" name = "username" value = "'. @$_POST['username']. '"></p>'; $returned[] = '<p>Password: <input type = "text" name = "password" value = "'. @$_POST['password']. '"></p>'; $returned[] = '</form>'; $returned[] = '</div>'; //header end $returned[] = "</div>"; $returned[] = "<div class = 'nav'><div class = 'values'>"; //nav start $cslinks = (array_values(database::query('menu', $nhmenu, 'menu')[0])[0]); $exlinks = explode(',', $cslinks); $i = 0; while($i < count($exlinks)) { if($exlinks[$i] == 'home') { $returned[] = "<a href = '". explode('/', $_SERVER['REQUEST_URI'])[0]. "index.php'>". $exlinks[$i]. "</a> | "; } else if($i != count($exlinks)-1) { $returned[] = "<a href = '". explode('/', $_SERVER['REQUEST_URI'])[0]. $exlinks[$i]. ".php'>". $exlinks[$i]. "</a> | "; } else { $returned[] = "<a href = '". explode('/', $_SERVER['REQUEST_URI'])[0]. $exlinks[$i]. ".php'>". $exlinks[$i]. "</a>"; } $i++; //sorts out returning the menu contents, their respective links and their display names } //nav end $returned[] = "</div></div>"; //echo start $i = 0; while($i < count($returned)) { echo($returned[$i]); $i++; } } public function get_pcontent() { $returned = array(); $confdir = ($_SERVER['DOCUMENT_ROOT']. '\site\config.xml'); $xml= simplexml_load_file($confdir); $post_page = ($xml->pagedata->post_page); $fpost_page = (string)$post_page; $url = explode('/', $_SERVER['SCRIPT_NAME']); $curl = $url[count($url)-1]; if($curl == $fpost_page) { $content = database::query('post', '6', 'posts'); if(count($content != 0)) { $returned = $content; $ordered = self::reorder($returned); $opnum = count($ordered)-1; $i = 0; while($opnum >= $i) { $blocks = (self::construct_block($ordered[$i])); $secopnum = count($blocks)-1; $q = 0; while($secopnum >= $q) { echo($blocks[$q]); $q++; } $i++; } } else { echo('nothing found'); } } } public function reorder($vals) { $array_vals = array_values($vals); $return = array(); $opnum = count($array_vals) - 1; while($opnum >= 0) { unset($array_vals[$opnum]['id']); $return[] = $array_vals[$opnum]; $opnum--; } return(self::structure($return)); } public function structure($vals) { $opnum = count($vals)-1; $tfvals = array(); $i = 0; while($opnum >= $i) { $elements = count($vals[$i])-1; $nvals = array_values($vals[$i]); $fvals = array(); $q = 0; while($elements >= $q) { $fvals[] = $nvals[$q]; $q++; } $tfvals[] = $fvals; $i++; } return $tfvals; } public function construct_block($vals) { $post = array(); $post[] = '<div class = "post">'; $opnum = count($vals)-1; $post[] = '<h4 id = "post_'. $vals[0].'">'. $vals[0]. '</h4>'; $post[] = '<img id = "fimage" src = "'. $vals[4]. '"></img><br></br>'; $post[] = '<span id = "categories">'. $vals[1]. '</span>'; $post[] = '<h5 id = "author">'. $vals[2]. '</h5>'; $post[] = '<span id = "time">'. self::dtformat($vals[3]). '</span>'; $post[] = '<p id = "shcontent">'. $vals[5]. '</p>'; $post[] = '<p id = "lhcontent">'. $vals[6]. '</p>'; $post[] = '</div>'; return($post); } public function dtformat($datetime) { return($datetime); } public function get_rmenu() { } } class database { public function connect() { $confdir = ($_SERVER['DOCUMENT_ROOT']. '\site\config.xml'); $xml= simplexml_load_file($confdir); $host = ($xml->database->host); $user = ($xml->database->user); $pass = ($xml->database->pass); $db = ($xml->database->db); $nhost = (string)$host; $nuser = (string)$user; $npass = (string)$pass; $ndb = (string)$db; $con= mysql_connect($nhost, $nuser, $npass); if (mysql_error()) { return false; } else { if(mysql_select_db($ndb)) { return true; } else { return false; } } } public function query($type, $find, $table) { if(self::connect()) { if($type == "menu") { $find = preg_replace("/\s+/", "", $find); $query = "SELECT `elements` FROM `$table` WHERE `title` = '$find'"; $qres = mysql_query($query); $qnum = mysql_num_rows($qres); $fresult = array(); $i = 0; while($i < $qnum) { $fresult[] = mysql_fetch_assoc($qres); $i++; } return($fresult); } else if($type == "page") { //create page table //construct page } else if($type == "post") { $find = preg_replace("/\s+/", "", $find); $query = "SELECT * FROM `$table`"; $qres = mysql_query($query); $qnum = mysql_num_rows($qres); $fresult = array(); $i = 0; while($i < $qnum && $i < $find) { $fresult[] = mysql_fetch_assoc($qres); $i++; } return($fresult); } else if($type == "menu") { //create menu table //construct menus } else if($type == "widget") { //create widget table //construct widgets } else { return(mysql_error()); } } } } ?>
Output for 5.4.0 - 7.1.0
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/I9p5o on line 30
Process exited with code 255.