3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Simplify { public static function URL($input) { // Alleen 5.4.0 en hoger!! return rtrim(preg_replace('/([^a-z0-9]+)/', '-', strtolower(preg_replace("/&([a-z])[a-z]+;/i", "$1", htmlentities($input)))), '-'); } public static function SSL() { // Reminder; controle op poort bijbouwen. return (isset( $_SERVER['HTTPS'] ) && !empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ? TRUE : FALSE); } public static function NoVarnish() { if (!headers_sent()) { header("Expires: Mon, 26 Jul 1990 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); return TRUE; } else { return FALSE; } } public static function CheckEmail($email) { // Reminder; even uitzoeken of filter_var wel beste oplossing is, misschien toch een preg_match? return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); } public static function CreateLinks($text) { // Zoeken naar url's en deze klikbaar maken met preg replace. return preg_replace('@(https?://([-\w.]+[-\w])+(:\d+)?(/([\w-.~:/?#\[\]\@!$&\'()*+,;=%]*)?)?)@', '<a href="$1" target="_blank">$1</a>', $text); } public static function ThisURL() { $url = ''; // Is ssl? Gebruik https ipv http if (self::SSL()) { $url .= 'https://'; } else { $url .= 'http://'; } $url .= $_SERVER['HTTP_HOST']; // Wanneer niet poort 80, de poort meenemen in url if ( $_SERVER['SERVER_PORT'] != 80 ) { $url .= ':' . $_SERVER['SERVER_PORT']; } // Is er een pad? if (!isset( $_SERVER['REQUEST_URI'])) { $url .= substr( $_SERVER['PHP_SELF'], 1 ); if (isset($_SERVER['QUERY_STRING'])) { $url .= '?' . $_SERVER['QUERY_STRING']; } } else { $url .= $_SERVER['REQUEST_URI']; } return $url; } public static function Random($max = 5) { // Random string van X karakters lang return substr(md5(microtime()),rand(0,26),$max); } public static function DownloadImage($url, $location) { try { $download = file_get_contents($url); file_put_contents($location, $download); return TRUE; } catch(Exception $ex){ return FALSE; } } public static function PostToVar($post) { try { foreach($post as $name => $content) { global ${$name}; ${$name} = $content; } } catch(Exception $e){ return FALSE; } } public static function Database($host, $user, $pass, $db) { $db = new mysqli($host, $user, $pass, $db); if ($db->connect_errno) { return FALSE; } else { return $db; } } public static function Country() { $api = "http://api.hostip.info/country.php?ip="; try { return (!isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? file_get_contents($api . $_SERVER['REMOTE_ADDR']) : FALSE); } catch(Exception $e){ return FALSE; } } public static function FBLikes($name) { $data = json_decode(file_get_contents("https://graph.facebook.com/".$name)); return $data->likes; } public static function FBCover($name) { $data = json_decode(file_get_contents("https://graph.facebook.com/".$name)); return $data->cover->source; } }
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/OAaej on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/OAaej on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/OAaej on line 5
Process exited with code 255.