3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /* IMPORT SPORTS CATEGORIES */ echo "import categories for lang=$lang\n"; $url = "https://www.bet3000.com/".$lang."/jsonrpc/?jsonrpc=2.0&id=0&method=sportsbook.get_active_categories"; try { $data = file_get_contents($url); $data = json_decode($data, true); $query = "UPDATE home_categories SET active=0"; if (!$debug) { mysql_query($query); } $cat_lvl_ids[0] = array("id" => 0,"label" => ""); $prev_lvl = 0; $parent_id = 0; $index = 0; $flag = false; $sortid=0; foreach ($data ['categories'] as $key => $value){ $sortid++; $cat = new Category($value); $lvl = $cat->get_level(); $id = $cat->get_id(); $active = $cat->get_activated_id(); $cat_lvl_ids[$lvl]["id"] = $id; $parent_id = $cat_lvl_ids[$lvl-1]["id"]; $parent_lbl = ""; if(!empty($cat_lvl_ids[$lvl-1]["label"])) { $parent_lbl = $cat_lvl_ids[$lvl-1]["label"]." / "; } $path = $parent_lbl . $cat->get_label(); $cat_lvl_ids[$lvl]["label"] = $path; $explode = explode(" / ",$path); $detail = $explode[count($explode)-1]; $sport = $explode[0]; $qcheck="SELECT * FROM `home_categories` WHERE cid=".$id." AND lang='".$lang."'"; $rcheck=mysql_query($qcheck); if (mysql_num_rows($rcheck)>0) { $ocheck=mysql_fetch_object($rcheck); $sqladd =""; $sqladd.= ",path='".trim(mysql_real_escape_string($path))."', detail='".trim(mysql_real_escape_string($detail))."'"; // UPDATE path,detail,sortid,active $querynew="UPDATE home_categories SET active=".$active.",sortid=".$sortid.$sqladd." WHERE cid=".$id." AND lang='".$lang."'"; mysql_query($querynew); echo mysql_error(); } else { $sqlheaderadd=""; $sqladd =""; $query = "INSERT IGNORE INTO `home_categories` (cid,lang,detail,path,topcatid,stufe,sport,sortid,active) VALUES (". $id.", ". "'".$lang."', ". "'".trim(mysql_real_escape_string($detail))."', ". "'".trim(mysql_real_escape_string($path))."', ". $parent_id.", ". $lvl.", ". "'".trim(mysql_real_escape_string($sport))."', ". $sortid.", ". $active. ")"; $resultInsert = mysql_query($query); if(!$resultInsert) echo mysql_error()."<br>$query"; } $prev_lvl = $lvl; } //foreach($result as $v) { // echo $value."<br>"; //} } catch(Exception $e) { echo $e->getMessage(); } echo 'Categories added to database'; class Category { private $id; private $lvl; private $label; private $activated_id; private $children; public function __construct($cat) { $this->id = $cat['id']; $this->lvl = $cat['level']; $this->label = $cat['label']; $this->activated_id = $cat['activated_id']; $this->children = array(); } public function get_id() { return $this->id; } public function get_level() { return $this->lvl; } public function get_label() { return $this->label; } public function get_activated_id() { return $this->activated_id; } public function get_children() { return $this->children; } public function set_id($id) { $this->id = $id; } public function set_level($lvl) { $this->lvl = $lvl; } public function set_label($label) { $this->label = $label; } public function set_children($children) { $this->children = $children; } public function add_child($child) { $this->children[] = $child; } public function get_child($index) { return $this->children[$index]; } public function remove_child($child,$index) { $this->children[] = null; } public function __toString() { return "Category Lvl:".$this->get_level()." - ".$this->get_id(). ":".$this->get_label(); } }
based on 5qu0C
Output for 7.0.20, 7.1.5 - 7.2.0
Notice: Undefined variable: lang in /in/gg4li on line 5 import categories for lang= Notice: Undefined variable: lang in /in/gg4li on line 6 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/gg4li on line 8 Warning: file_get_contents(https://www.bet3000.com//jsonrpc/?jsonrpc=2.0&id=0&method=sportsbook.get_active_categories): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/gg4li on line 8 Notice: Undefined variable: debug in /in/gg4li on line 12 Fatal error: Uncaught Error: Call to undefined function mysql_query() in /in/gg4li:12 Stack trace: #0 {main} thrown in /in/gg4li on line 12
Process exited with code 255.
Output for 7.0.0 - 7.0.10, 7.1.0
Notice: Undefined variable: lang in /in/gg4li on line 5 import categories for lang= Notice: Undefined variable: lang in /in/gg4li on line 6 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/gg4li on line 8 Warning: file_get_contents(https://www.bet3000.com//jsonrpc/?jsonrpc=2.0&id=0&method=sportsbook.get_active_categories): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/gg4li on line 8 Notice: Undefined variable: debug in /in/gg4li on line 12 Fatal error: Uncaught Error: Call to undefined function mysql_query() in /in/gg4li:12 Stack trace: #0 {main} thrown in /in/gg4li on line 12
Process exited with code 255.
Output for 5.4.15 - 5.6.28
Notice: Undefined variable: lang in /in/gg4li on line 5 import categories for lang= Notice: Undefined variable: lang in /in/gg4li on line 6 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/gg4li on line 8 Warning: file_get_contents(https://www.bet3000.com//jsonrpc/?jsonrpc=2.0&id=0&method=sportsbook.get_active_categories): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/gg4li on line 8 Notice: Undefined variable: debug in /in/gg4li on line 12 Fatal error: Call to undefined function mysql_query() in /in/gg4li on line 12
Process exited with code 255.
Output for 5.3.0 - 5.4.14
Notice: Undefined variable: lang in /in/gg4li on line 5 import categories for lang= Notice: Undefined variable: lang in /in/gg4li on line 6 Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/gg4li on line 8 Warning: file_get_contents(https://www.bet3000.com//jsonrpc/?jsonrpc=2.0&id=0&method=sportsbook.get_active_categories): failed to open stream: No such file or directory in /in/gg4li on line 8 Notice: Undefined variable: debug in /in/gg4li on line 12 Fatal error: Call to undefined function mysql_query() in /in/gg4li on line 12
Process exited with code 255.
Output for 5.2.0 - 5.2.17
Notice: Undefined variable: lang in /in/gg4li on line 5 import categories for lang= Notice: Undefined variable: lang in /in/gg4li on line 6 Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/gg4li on line 8 Warning: file_get_contents(https://www.bet3000.com//jsonrpc/?jsonrpc=2.0&id=0&method=sportsbook.get_active_categories): failed to open stream: No such file or directory in /in/gg4li on line 8 Notice: Undefined variable: debug in /in/gg4li on line 12 Fatal error: Call to undefined function mysql_query() in /in/gg4li on line 12
Process exited with code 255.
Output for 5.0.4 - 5.1.6
Notice: Undefined variable: lang in /in/gg4li on line 5 import categories for lang= Notice: Undefined variable: lang in /in/gg4li on line 6 Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/gg4li on line 8 Warning: file_get_contents(https://www.bet3000.com//jsonrpc/?jsonrpc=2.0&id=0&method=sportsbook.get_active_categories): failed to open stream: No such file or directory in /in/gg4li on line 8 Fatal error: Call to undefined function json_decode() in /in/gg4li on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: lang in /in/gg4li on line 5 import categories for lang= Notice: Undefined variable: lang in /in/gg4li on line 6 Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/gg4li on line 8 Warning: file_get_contents(https://www.bet3000.com//jsonrpc/?jsonrpc=2.0&id=0&method=sportsbook.get_active_categories): failed to open stream: No such file or directory in /in/gg4li on line 8 Fatal error: Call to undefined function json_decode() in /in/gg4li on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{' in /in/gg4li on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '{' in /in/gg4li on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/gg4li on line 7
Process exited with code 255.