3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Global vars */ $statuses = array(0 => 'Not for Sale', 1 => 'For Sale', 2 => 'Sold', 4 => 'Expired'); $tlds = array('com', 'tv', 'me', 'org', 'net'); /** * Get tags */ function tags_to_array($tags) { $tags = trim($tags, '#'); if (!strlen($tags)) return array(); return explode('#', $tags); } function array_to_tags($tags = array()) { if (!count($tags)) return ''; return '#'.implode('#', $tags).'#'; } function get_tags($id = NULL) { global $db; $tags = array(); if ($id) { $tags = $db->query("SELECT tags FROM domains WHERE id = '$id'", true); $tags = tags_to_array($tags['tags']); $tags = get_tag_by_id($tags); return $tags; } global $Cache; if ($tags = $Cache->get('tags')) return $tags; $gettags = $db->query("SELECT * FROM tags"); if ($db->num_rows($gettags) > 0) { while ($row = $db->fetch_array($gettags)) { $tags[$row['id']] = $row; } } $Cache->save($tags); return $tags; } function get_tag_by_id($ids = array()) { $tags = array(); if (!count($ids)) return array(); $alltags = get_tags(); foreach ($ids as $id) { $tags[$id] = $alltags[$id]; } return $tags; } function get_domains($query) { global $db; $getdomains = $db->query("$query") or $db->raise_error(); $domains = array(); if (count($getdomains > 0)) { include('./includes/colors.php'); $used_colors = array(0, 0, 0, 0); $color_index = array_keys($colors); while ($domain = $db->fetch_array($getdomains)) { $color = array_rand(array_diff($color_index, $used_colors)); array_shift($used_colors); $used_colors[] = $color; $domain['colors'] = $colors[$color]; $domain['name'] = explode('.', $domain['domain']); $domain['name'] = $domain['name'][0]; $domains[] = $domain; } $db->free_result($getdomains); } return $domains; } /** * Strip any unsafe tags/chars/attributes from input values. * * @param string $value Value to be cleaned * @param boolean $strip_crlf Strip \r\n ? * @param boolean $is_email If the value is an email, pass it through the email sanitize filter. * @return string Sanitized value. */ function sanitize($value, $strip_crlf = true, $is_email = false) { $value = preg_replace('@&(?!(#[0-9]+|[a-z]+);)@si', '', $value); if ($is_email) { /** * PHP versions older than 5.2.11 have bugs in FILTER_SANITIZE_EMAIL * It allows characters that shouldn't be allowed. * * We will only sanitize the email if they are using 5.2.11 and greater. * This shouldn't pose a problem on < 5.2.11 cause we validate the email * later on anyway. */ if (version_compare(PHP_VERSION, '5.2.11', '>=')) { $value = filter_var($value, FILTER_SANITIZE_EMAIL); } } else { $value = filter_var($value, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); } // This will strip new line characters if $strip_crlf is set to true. if ($strip_crlf) { $value = preg_replace('@([\r\n])[\s]+@', '', $value); } return clean($value); } /** * Clean values pulled from the database, although could be used on anything. * * Cleans either a string, or can clean an entire array of values: * clean($array); * * @param mixed $value Value to be cleaned * @return mixed Cleaned array or string. */ function clean($value) { if (is_array($value)) { foreach ($value AS $key => $val) { if (is_string($val)) { $value["$key"] = trim(stripslashes($val)); } else if (is_array($val)) { $value["$key"] = clean($value["$key"]); } } return $value; } return trim(stripslashes($value)); } /** * Will make sure a variable is valid. * * @param string $option What to check * @param mixed $value What to check's value. * @return mixed Depending on the $option, could return a string, NULL, or boolean. */ function is($option, $value) { global $db; switch ($option) { case 'orderby': if (!in_array($value, array('added', 'domain', 'registrar', 'history', 'price', 'exp', 'status'))) { return 'domain'; } break; case 'email': return (bool)(preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>]+\.+[a-z]{2,6}))$#si', $value)); break; case 'injection': return (bool)(preg_match('#(To:|Bcc:|Cc:|Content-type:|Mime-version:|Content-Transfer-Encoding:)#i', urldecode($value))); break; case 'spam': preg_match_all('#(<a href|\[url|http[s]?://)#i', $value, $matches, PREG_PATTERN_ORDER); return (bool)(count($matches[0]) > 2); break; case 'domain': list($name, $tld) = explode('.', strtolower(trim($value)), 2); $getdomain = $db->query("SELECT * FROM domains WHERE name = '$name' AND tld = '$tld'", true); $ret = count($getdomain) ? $getdomain : false; $db->free_result($getdomain); return $ret; break; case 'tag': if ($value === '') return ''; $tags = get_tags(); $slug = strtolower(str_replace(' ', '-', trim($value))); $res = false; foreach ($tags as $tag) { if ($tag['slug'] == $slug) { $res = $tag; break; } } return $res; break; case 'tld': if ($value === '') { return ''; } if ($value == 'tlds') { return 'tlds'; } $gettld = $db->query("SELECT * FROM tld WHERE tld = '$value'", true); $tld = count($gettld) ? $gettld : false; $db->free_result($gettld); return $tld; break; } return $value; } /** * Get the users ip address. * * @param void * @return string IP Address */ function get_ip() { $ip = _getenv('REMOTE_ADDR'); if (_getenv('HTTP_X_FORWARDED_FOR')) { if (preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', _getenv('HTTP_X_FORWARDED_FOR'), $matches)) { foreach ($matches[0] AS $match) { if (!preg_match('#^(10|172\.16|192\.168)\.#', $match)) { $ip = $match; break; } } unset($matches); } } else if (_getenv('HTTP_CLIENT_IP')) { $ip = _getenv('HTTP_CLIENT_IP'); } else if (_getenv('HTTP_FROM')) { $ip = _getenv('HTTP_FROM'); } if (!filter_var($ip, FILTER_VALIDATE_IP)) { return '0.0.0.0'; } return $ip; } /** * Returns an environment variable. * * @param string $varname Variable name, eg: PHP_SELF * @return string Variable's value. */ function _getenv($varname) { if (isset($_SERVER[$varname])) { return $_SERVER[$varname]; } else if (isset($_ENV[$varname])) { return $_ENV[$varname]; } return ''; } /** * A wrapper for date that will format dates using the UTC timezone. * This is used for domain history dates as UTC is pretty much * the standard for domain history dates. * * @param string $format Date format * @param integer $timestamp Unix timestamp * @return string Formatted date */ function _date($format, $timestamp) { if (!$timestamp) { return ''; } // Get the current timezone $current_tz = date_default_timezone_get(); // Set to UTC, as that's pretty much the standard for domain expiration date_default_timezone_set('UTC'); // format the time $date = date($format, $timestamp); // Set back to old timezone date_default_timezone_set($current_tz); return $date; } /** * Returns a md5'ed hash. * * @param string $string String to hash * @return string Hash */ function _hash($string) { return hash('md5', $string); } /** * Helper function for encode_email * * @param string $char Character to encode. * @return string Encoded character. */ function _encode_email_helper($char = 0) { return '&#' . ord($char) . ';'; } /** * Encodes an email address, if that email is valid. * * At this time, this will mainly be used on database error pages, that * places the email address in HTML. * * @param string $email Email address to encode. * @return string Encoded email address if valid, or plain email if not valid. */ function encode_email($email) { if (is('email', $email)) { $chars = str_split($email); $encoded = filter_var($chars, FILTER_CALLBACK, array('options' => '_encode_email_helper')); $encoded = implode('', $encoded); unset($chars); return $encoded; } return $email; } /** * Redirects to another URL. * * @param string $url Destination url * @return void */ function redirect($url) { //if (count($_SESSION)) //{ //session_write_close(); //} $url = filter_var($url, FILTER_SANITIZE_URL); header("Location: $url", true, 302); exit; } /** * Generates the pagination. * * @param integer $numresults Total number of results. * @param integer $page Current page * @param string $orderby Sort order * @param string $search Search query (will only be used for search.php) * @return array Array consisting of SQL limit, and pagination links. */ function paginate($numresults, $page, $params = array(), $perpage = NULL) { global $config; $pager = ''; $limit = 0; $extra = ''; $perpage = is_null($perpage) ? intval($config['maxperpage']) : intval($perpage); if ($numresults <= $perpage) { return array('pager' => '', 'limit' => 0); } $numpages = ceil($numresults / $perpage); $page = intval(abs($page)); $page = ($page < 1) ? 1 : ($page > $numpages ? $numpages : $page); $limit = ($page - 1) * $perpage; // Any params? if (!empty($params)) { $extra = '&amp;' . sanitize(http_build_query($params)); } for ($i = 1; $i <= $numpages; ++$i) { if ($page == $i) { $pager .= "<li><span class=\"current\">$i</span></li>"; } else { $pager .= "<li><a href=\"?page=$i$extra\">$i</a></li>"; } } if (strlen($pager)) { $pager = '<ul class="pagination">'.$pager.'</ul>'; } return array( 'limit' => $limit, 'pager' => $pager ); } /** * Builds the HTML for tags and latest domains added. * * @param string $list Which list to build. * @return string List HTML */ function build_list($list) { global $db, $config, $path, $tlds; switch ($list) { case 'tags': $tags = get_tags(); if (count($tags)) { $n = 0; foreach ($tags as $tag) { $n += $tag['num']; $active = ($path[0] == 'domains' && $path[1] == $tag['slug']) ? ' active' : ''; $listhtml .= "<a href=\"/domains/$tag[slug]\" class=\"tag$active\">$tag[tag]<span class=\"count\">$tag[num]</span></a>"; } } else { $listhtml = 'No Tags Yet'; } return $listhtml; break; case 'tld': $listhtml = array(); $gettlds = $db->query("SELECT * FROM tld ORDER BY tld ASC") or $db->raise_error(); if ($db->num_rows($gettlds) > 0) { $n = 0; $m = 0; $col = 0; $collapsed = array('net', 'org'); $colslug = implode('+', $collapsed); while ($row = $db->fetch_array($gettlds)) { $n += $row['num']; if (!in_array($row['tld'], $tlds)) { $m += $row['num']; continue; } if (in_array($row['tld'], $collapsed)) { $col += $row['num']; continue; } $active = ($path[0] == 'domains' && $path[1] == $row['tld']) ? ' active' : ''; $listhtml[$row['tld']] = "<a href=\"/domains/$row[tld]\" class=\"tld$active\">.$row[tld]<span class=\"count\">$row[num]</span></a>"; } $active = ($path[0] == 'domains' && !$path[1]) ? ' active' : ''; $html = '<a href="/domains" id="showall" class="tld'.$active.'">.ALL<span class="count">'.$n.'</span></a>'; foreach ($tlds as $tld) { $html .= $listhtml[$tld]; } $active = ($path[0] == 'domains' && $path[1] == $colslug) ? ' active' : ''; $html .= '<a href="/domains/'.$colslug.'" class="tld'.$active.'">.net + .org<span class="count">'.$col.'</span></a>'; $active = ($path[0] == 'domains' && $path[1] == 'others') ? ' active' : ''; $html .= '<a href="/domains/others" class="tld'.$active.'">.others<span class="count">'.$m.'</span></a>'; } else { $html = 'No Extensions Yet'; } $db->free_result($gettlds); return $html; break; case 'latest': $getlatest = $db->query("SELECT id, domain, added FROM domains WHERE status != 0 AND status != 2 ORDER BY added DESC LIMIT 5") or $db->raise_error(); if ($db->num_rows($getlatest) == 0) { $listhtml = '<li>None</li>'; } else { while ($latest = $db->fetch_array($getlatest)) { $date = date('m/d/Y', $latest['added']); $listhtml .= "<li><a href=\"details?d=$latest[id]\" title=\"Details for $latest[domain]\">$latest[domain]</a> ($date)</li>\n"; $listhtml = trim($listhtml); } } $db->free_result($getlatest); return trim($listhtml); break; default: break; } } /* Build domain HTML list for a frontend domains.tpl/search.tpl */ function build_domain_list($domains=array()) { if (empty($domains)) echo ''; foreach ($domains as $domain) { echo '<a class="domain" style="background:#' . $domain['colors'][0] . ';color:#' . $domain['colors'][1] . ';" href="/' . $domain['domain']' . ">'; //$d = in_array($domain['tld'], array('me', 'ly', 'tv')) ? '<span class="ext">.'.$domain['tld'].'</span>' : ''; if ($domain['tld'] == 'tv') { $t = 'TV'; } elseif ($domain['tld'] == 'me') { $t = 'Me'; } else { $t = $domain['tld']; } echo '<div class="name'; if (strlen($domain['name']) > 16) echo ' long'; echo '">' . $domain['name'] . '</div><div class="dpanel">' . $domain['name'] . '.' . $t . '</div></a>'; } } /** * Builds the 'hide' dropdown menu in admin for the edit page. * * @param string $option Which select to build. * @param string $value Select's value. * @return string The $option's HTML */ function build_select($option, $value = '') { global $db; $select = ''; switch ($option) { case 'status': global $statuses; $value = ($value === '') ? 1 : $value; foreach ($statuses AS $key=>$val) { $select .= "<option label=\"$val\" value=\"$key\"" . ($value == $key ? ' selected="selected"' : '') . ">$val</option>\n"; } break; case 'tags': $select = ''; $domain_tags = array(); $tags = get_tags(); if ($value !== '') { $domain_tags = array_keys(get_tags($value)); } $select .= '<div class="row tags">'; foreach ($tags as $tag) { $tagged = in_array($tag['id'], $domain_tags) ? true : false; $selected = $tagged ? ' selected ' : ''; $checked = $tagged ? ' checked="checked" ' : ' '; $select .= '<div class="col-md-4'.$selected.'" data-tag="'.$tag['id'].'">'; $select .= '<input type="checkbox"'.$checked.'name="tags[]" value="'.$tag['id'].'">&nbsp;<span>'.$tag['tag'].'</span></div>'; } $select .= '</div>'; break; case 'colors': $select = ''; include('colors.php'); $select .= '<div class="row colors">'; foreach ($colors as $code => $color) { $select .= '<div class="col-md-2" id="color'.$code.'" style="background:#'.$color[0].';color:#'.$color[1].';" onclick="selectColor(this)">Name</div>'; } $select .= '</div>'; } return $select; } function message($message = NULL, $code = NULL) { if (!$message) { if (isset($_SESSION['messages']) && !empty($_SESSION['messages'])) { $out = ''; foreach ($_SESSION['messages'] as $message) { $out .= '<div class="alert alert-' . $message[1] . '">' . $message[0] . '</div>'; } echo $out; unset($_SESSION['messages']); } return; } $codes = array('success', 'info', 'warning', 'danger'); if (!$code || !in_array($code, $codes)) { $code = 'info'; } if (!isset($_SESSION['messages'])) { $_SESSION['messages'] = array(); } $_SESSION['messages'][] = array($message, $code); } /** * Returns a 'nice', human-readable size - thanks to WordPress * * @param integer $bytes Size to format * @return string Human-readable size. */ function size_format($bytes) { $quant = array( 'TB' => pow(1024, 4), 'GB' => pow(1024, 3), 'MB' => pow(1024, 2), 'kB' => pow(1024, 1), 'B' => pow(1024, 0) ); foreach ($quant AS $unit => $mag) { if (intval($bytes) >= $mag) { return number_format($bytes / $mag) . " $unit"; } } return '-'; } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.290.0070.05412.67
5.4.280.0160.08412.54
5.4.270.0100.04412.53
5.4.260.0110.06112.53
5.4.250.0350.11312.54
5.4.240.0220.04412.54
5.4.230.0080.06012.53
5.4.220.0310.09112.53
5.4.210.0150.09012.53
5.4.200.0090.04212.53
5.4.190.0100.05312.52
5.4.180.0130.03712.52
5.4.170.0110.05712.53
5.4.160.0130.04512.52
5.4.150.0100.03712.52
5.4.140.0080.04012.21
5.4.130.0060.04312.19
5.4.120.0080.03812.16
5.4.110.0120.04512.15
5.4.100.0090.04312.16
5.4.90.0090.04012.16
5.4.80.0070.05512.16
5.4.70.0150.05212.15
5.4.60.0140.04812.15
5.4.50.0080.05712.16
5.4.40.0190.06012.14
5.4.30.0150.05112.14
5.4.20.0170.07312.13
5.4.10.0110.06912.14
5.4.00.0140.08411.63
5.3.280.0130.05512.82
5.3.270.0190.09712.84
5.3.260.0110.05912.84
5.3.250.0130.04912.84
5.3.240.0150.05312.84
5.3.230.0200.10412.84
5.3.220.0170.05712.81
5.3.210.0110.07012.81
5.3.200.0170.07912.81
5.3.190.0180.06412.81
5.3.180.0130.07612.80
5.3.170.0180.10012.81
5.3.160.0150.08312.80
5.3.150.0180.07312.80
5.3.140.0140.07612.80
5.3.130.0120.04912.79
5.3.120.0100.05812.79
5.3.110.0120.05912.79
5.3.100.0100.05312.27
5.3.90.0190.10112.25
5.3.80.0070.05312.24
5.3.70.0210.08012.21
5.3.60.0140.05512.22
5.3.50.0110.06012.17
5.3.40.0140.04812.17
5.3.30.0190.06712.13
5.3.20.0140.05111.91
5.3.10.0130.07711.88
5.3.00.0120.07111.87

preferences:
136.21 ms | 1398 KiB | 7 Q