3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('Europe/Athens'); // Create connection $conn = new mysqli("mysql.freehostia.com", "dimpou5_forum", "stella_0", "dimpou5_forum", 3306); $conn->set_charset("utf8"); $tablePrefix = ""; // Check connection if ($conn->connect_error) die("Connection failed: " . $conn->connect_error); /* $rows = array(); $sql = "SELECT * FROM structure"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { //echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>"; $rows[] = $row; } } else { echo "0 results"; } $count_last_category = 0; $tree = buildTree($rows); $list_dom = print_ols($tree); echo $count_last_category; echo $list_dom; echo "\n"; echo date("d-m-Y") . "\n"; echo strtotime(date("d-m-Y")) . "\n"; print_r( skroutz_getPriceFromLink("http://www.skroutz.gr/s/6535417/Manta-MS1701.html")); */ $sql = "SELECT * FROM ".$tablePrefix."structure WHERE path LIKE '%kinhta%' LIMIT 1"; $result = $conn->query($sql); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $subcategory_url = $row['scheme'] . "://" . $row['host'] . $row['path']; skroutz_updateSubcategoriesProducts($subcategory_url, $conn, 1); echo "<span style='font-size: 15; font-weight: bold; color: green'>DONE! :)</span>"; } else { echo "0 results"; } /** apo edw 3ekiname */ function skroutz_updateSubcategoriesProducts($url, $connection, $sleep){ $numOfPages = skroutz_getNumOfPages($url); for ($i=1; $i <= $numOfPages; $i++) { $page_products = skroutz_getPageProducts($url . "?page=" . $i); skroutz_products_insert_update($page_products, $connection); sleep($sleep); } } //voithitiki //edw metrame poses selides exei.. //pernoume ola ta li pou einai mesa se class 'paginator' (einai apo dio fores, alla den mas niazei) //giati to proteleutaio theloume function skroutz_getNumOfPages($url){ $output = file_get_contents($url); $dom_output = new DomDocument(); @$dom_output->loadHTML(mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8')); $finder = new DomXPath($dom_output); $nodes = $finder->query("//*[contains(@class, 'paginator')]//li"); return $nodes->item($nodes->length-2)->nodeValue; } function skroutz_getPageProducts($url){ $output = file_get_contents($url); $dom_output = new DomDocument(); @$dom_output->loadHTML(mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8')); $finder = new DomXPath($dom_output); $products = array(); $nodes = $finder->query("//*[contains(@id, 'sku_list')]//li[contains(@class, 'line')]"); foreach($nodes as $i => $node){ $name = $finder->query("div[contains(@class, 'details')]/h2/a", $node)->item(0); $link = parse_url($name->getAttribute('href')); if(!isset($link['host'])){ $link['scheme'] = "http"; $link['host'] = "www.skroutz.gr"; } $price = trim($finder->query("p[contains(@class, 'price')]//a", $node)->item(0)->nodeValue); $price = str_replace(array(","," €"), "", $price); $products[$i]['id'] = skroutz_getProductIdFromUrl($name->getAttribute('href')); $products[$i]['category_id'] = skroutz_getCategoryIdFromUrl($url); $products[$i]['name'] = trim($name->nodeValue); $products[$i]['price']['date'] = date("Ymd"); $products[$i]['price']['value'] = $price; $products[$i]['scheme'] = $link['scheme']; $products[$i]['host'] = $link['host']; $products[$i]['path'] = $link['path']; } return $products; } /* skroutz_products_insert_update: pernei enan pinaka tis parakatw morfis kai ton vazei mesa ston pinaka 'products' KAI 'prices' * Array * ( * [0] => Array * ( * [id] => 6535417 * [category_id] => 40 * [name] => Manta MS1701 * [price] => Array * ( * [date] => 20151118 * [value] => 1580 * ) * * [scheme] => http * [host] => www.skroutz.gr * [path] => /s/6535417/Manta-MS1701.html * ) * [1] => Array * ( * .... * ) **/ function skroutz_products_insert_update($array, $connection){ global $tablePrefix; foreach ($array as $key => $value) { $sql = "INSERT INTO ".$tablePrefix."products (id, category_id, name, scheme, host, path) VALUES ('$value[id]', '$value[category_id]', '" . mysqli_real_escape_string($connection ,$value['name']) . "', '$value[scheme]', '$value[host]', '$value[path]') ON DUPLICATE KEY UPDATE category_id='$value[category_id]', name='" . mysqli_real_escape_string($connection, $value['name']) . "'"; if ($connection->query($sql) === TRUE) { echo "$value[name] .................successfully<br>\n"; } else { echo "Error: " . $sql . "<br>" . $connection->error; } $sql = "INSERT INTO ".$tablePrefix."prices (id, date, price, lastUpdate) VALUES ('$value[id]', '".$value["price"]["date"]."', '".$value["price"]["value"]."', NOW()) ON DUPLICATE KEY UPDATE price='".$value["price"]["value"]."', lastUpdate=NOW()"; if ($connection->query($sql) === TRUE) { echo "$value[name] .................successfully<br>\n"; } else { echo "Error: " . $sql . "<br>" . $connection->error; } } } /* function skroutz_getPageProducts($url){ $output = file_get_contents($url); $dom_output = new DomDocument(); @$dom_output->loadHTML(mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8')); $finder = new DomXPath($dom_output); $products = array(); $nodes = $finder->query("//*[contains(@id, 'sku_list')]//li[contains(@class, 'line')]//h2//a"); foreach($nodes as $i => $node){ $link = parse_url($node->getAttribute('href')); if(!isset($link['host'])){ $link['scheme'] = "http"; $link['host'] = "www.skroutz.gr"; } $products[$i]['id'] = skroutz_getProductIdFromUrl($node->getAttribute('href')); $products[$i]['category_id'] = skroutz_getCategoryIdFromUrl($url); $products[$i]['name'] = trim($node->nodeValue); $products[$i]['scheme'] = $link['scheme']; $products[$i]['host'] = $link['host']; $products[$i]['path'] = $link['path']; } return $products; } */ $conn->close(); //den xrisimopoieite pros to paron function skroutz_getPriceFromLink($link){ $link_json = substr($link, 0, -5) . "/price_graph.json"; $output = json_decode(file_get_contents($link_json)); $index = count($output->min_price->recent) - 1; $current_price = $output->min_price->recent[$index]; return $current_price; } function print_ols($array){ global $count_last_category; $return = "<ol>"; foreach ($array as $key => $value) { $return .= "<li value='$value[id]'>"; $return .= $value['name']; if(isset($value['children'])) $return .= print_ols($value['children']); else $count_last_category++; $return .= "</li>"; } $return .= "</ol>"; return $return; } //http://stackoverflow.com/questions/8587341/recursive-function-to-generate-multidimensional-array-from-database-result function buildTree(array $elements, $parentId = 0) { $branch = array(); foreach ($elements as $element) { if ($element['parent_id'] == $parentId) { $children = buildTree($elements, $element['id']); if ($children) { $element['children'] = $children; } $branch[] = $element; } } return $branch; } //voithitiki function skroutz_getCategoryIdFromUrl($url){ $parts = explode('/', $url); foreach ($parts as $key => $value) { if ($value == "c"){ return $parts[$key + 1]; } } return 0; //an ftasei mexri edw, den exei parent } //voithitiki function skroutz_getProductIdFromUrl($url){ $parts = explode('/', $url); foreach ($parts as $key => $value) { if ($value == "s"){ return $parts[$key + 1]; } } return 0; //an ftasei mexri edw, den exei parent } ?>
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Class "mysqli" not found in /in/DJqad:5 Stack trace: #0 {main} thrown in /in/DJqad on line 5
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
54.95 ms | 401 KiB | 8 Q