3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Future-friendly json_encode if(!function_exists('json_encode')) { //require_once dirname(__FILE__) '/JSON.php'; function json_encode($data) { //$json = new Services_JSON(); //return $json->encode($data); } } // Future-friendly json_decode if(!function_exists('json_decode')) { //require_once dirname(__FILE__) '/JSON.php'; function json_decode($data) { //$json = new Services_JSON(); //return $json->decode($data); } } /** * Premailer API PHP class * Premailer is a library/service for making HTML more palatable for various inept email clients, in particular GMail * Primary function is to convert style tags into equivalent inline styles so styling can survive <head> tag removal * Premailer is owned by Dialect Communications group * @link http://premailer.dialect.ca/api * @author Marcus Bointon <marcus@synchromedia.co.uk> */ /** * The Premailer API URL */ define('PREMAILER_ENDPOINT', 'http://premailer.dialect.ca/api/0.1/documents'); class Premailer { /** * Central static method for submitting either an HTML string or a URL, optionally retrieving converted versions * @static * @throws Exception * @param string $html Raw HTML source * @param string $url URL of the source file * @param bool $fetchresult Whether to also fetch the converted output * @param string $adaptor Which document handler to use (hpricot (default) or nokigiri) * @param string $base_url Base URL for converting relative links * @param int $line_length Length of lines in the plain text version (default 65) * @param string $link_query_string Query string appended to links * @param bool $preserve_styles Whether to preserve any link rel=stylesheet and style elements * @param bool $remove_ids Remove IDs from the HTML document? * @param bool $remove_classes Remove classes from the HTML document? * @param bool $remove_comments Remove comments from the HTML document? * @return array Either a single strclass object containing the decoded JSON response, or a 3-element array containing result, html and plain parts if $fetchresult is set */ /*static*/ function convert($html = '', $url = '', $fetchresult = true, $adaptor = 'hpricot', $base_url = '', $line_length = 65, $link_query_string = '', $preserve_styles = true, $remove_ids = false, $remove_classes = false, $remove_comments = false) { $params = array(); if (!empty($html)) { $params['html'] = $html; } elseif (!empty($url)) { $params['url'] = $url; } else { trigger_error('Must supply an html or url value', E_USER_WARNING); return -1; } if ($adaptor == 'hpricot' or $adaptor == 'nokigiri') { $params['adaptor'] = $adaptor; } if (!empty($base_url)) { $params['base_url'] = $base_url; } $params['line_length'] = (integer)$line_length; if (!empty($link_query_string)) { $params['link_query_string'] = $link_query_string; } $params['preserve_styles'] = ($preserve_styles?'true':'false'); $params['remove_ids'] = ($remove_ids?'true':'false'); $params['remove_classes'] = ($remove_classes?'true':'false'); $params['remove_comments'] = ($remove_comments?'true':'false'); $options = array( 'timeout' => 15, 'connecttimeout' => 15, 'useragent' => 'PHP Premailer', 'ssl' => array('verifypeer' => false, 'verifyhost' => false) ); // $h = new HttpRequest(self::ENDPOINT, HttpRequest::METH_POST, $options); $conf = array( 'url' => PREMAILER_ENDPOINT, 'timeout' => 15, 'useragent' => 'PHP Premailer', 'ssl_verifyhost' => 0, 'SSL_VERIFYPEER' => 0, 'post' => 1, 'postfields' => $params, 'returntransfer' => true, 'httpheader' => array("Expect:") ); foreach($conf as $key => $value){ $name = constant('CURLOPT_'.strtoupper($key)); $val = $value; $data_conf[$name] = $val; } $cu = curl_init(); curl_setopt_array($cu, $data_conf); $exec = curl_exec($cu); $_res = json_decode($exec); $_res_info = json_decode(json_encode(curl_getinfo($cu))); curl_close($cu); if($_res_info->http_code != 201){ $code = $_res_info->http_code; switch ($code) { case 400: trigger_error('Content missing', E_USER_WARNING); return -1; break; case 403: trigger_error('Access forbidden', E_USER_WARNING); return -1; break; case 500: default: trigger_error('Error '.$code, E_USER_WARNING); return -1; } } $return = array('result' => $_res); if ($fetchresult) { $html = curl_init(); curl_setopt_array( $html, array( CURLOPT_URL => $_res->documents->html, CURLOPT_TIMEOUT => 15, CURLOPT_USERAGENT => 'PHP Premailer', CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_HTTPHEADER => array("Expect:"), CURLOPT_RETURNTRANSFER => true ) ); $return['html'] = curl_exec($html); curl_close($html); $plain = curl_init(); curl_setopt_array( $plain, array( CURLOPT_URL => $_res->documents->txt, CURLOPT_TIMEOUT => 15, CURLOPT_USERAGENT => 'PHP Premailer', CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_HTTPHEADER => array("Expect:"), CURLOPT_RETURNTRANSFER => true ) ); $return['plain'] = curl_exec($plain); curl_close($plain); return $return; } return $result; } /** * Central static method for submitting either an HTML string or a URL, optionally retrieving converted versions * @static * @throws Exception * @param string $html Raw HTML source * @param bool $fetchresult Whether to also fetch the converted output * @param string $adaptor Which document handler to use (hpricot (default) or nokigiri) * @param string $base_url Base URL for converting relative links * @param int $line_length Length of lines in the plain text version (default 65) * @param string $link_query_string Query string appended to links * @param bool $preserve_styles Whether to preserve any link rel=stylesheet and style elements * @param bool $remove_ids Remove IDs from the HTML document? * @param bool $remove_classes Remove classes from the HTML document? * @param bool $remove_comments Remove comments from the HTML document? * @return array Either a single element array containing the 'result' object, or three elements containing result, html and plain if $fetchresult is set */ /*static*/ function html($html, $fetchresult = true, $adaptor = 'hpricot', $base_url = '', $line_length = 65, $link_query_string = '', $preserve_styles = true, $remove_ids = false, $remove_classes = false, $remove_comments = false) { return Premailer::convert($html, '', $fetchresult, $adaptor, $base_url, $line_length, $link_query_string, $preserve_styles, $remove_ids, $remove_classes, $remove_comments); } /** * Central static method for submitting either an HTML string or a URL, optionally retrieving converted versions * @static * @throws Exception * @param string $url URL of the source file * @param bool $fetchresult Whether to also fetch the converted output * @param string $adaptor Which document handler to use (hpricot (default) or nokigiri) * @param string $base_url Base URL for converting relative links * @param int $line_length Length of lines in the plain text version (default 65) * @param string $link_query_string Query string appended to links * @param bool $preserve_styles Whether to preserve any link rel=stylesheet and style elements * @param bool $remove_ids Remove IDs from the HTML document? * @param bool $remove_classes Remove classes from the HTML document? * @param bool $remove_comments Remove comments from the HTML document? * @return array Either a single element array containing the 'result' object, or three elements containing result, html and plain if $fetchresult is set */ /*static*/ function url($url, $fetchresult = true, $adaptor = 'hpricot', $base_url = '', $line_length = 65, $link_query_string = '', $preserve_styles = true, $remove_ids = false, $remove_classes = false, $remove_comments = false) { return Premailer::convert('', $url, $fetchresult, $adaptor, $base_url, $line_length, $link_query_string, $preserve_styles, $remove_ids, $remove_classes, $remove_comments); } } /* Simplest usage: $pre = Premailer::html($var_with_some_html_in); $html = $pre['html']; $plain = $pre['plain']; //Similarly for URLs: $pre = Premailer::url($url); */

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)
8.3.60.0070.00718.43
8.3.50.0110.00922.06
8.3.40.0120.00918.79
8.3.30.0070.00719.27
8.3.20.0080.00020.41
8.3.10.0080.00020.36
8.3.00.0050.00318.05
8.2.180.0120.00616.88
8.2.170.0030.01522.96
8.2.160.0040.01120.57
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0060.00326.16
8.2.120.0030.00522.12
8.2.110.0090.00021.18
8.2.100.0070.00417.84
8.2.90.0030.00619.17
8.2.80.0080.00017.97
8.2.70.0080.00017.75
8.2.60.0060.00317.91
8.2.50.0050.00318.07
8.2.40.0080.00018.20
8.2.30.0030.00619.33
8.2.20.0030.00517.62
8.2.10.0000.00718.23
8.2.00.0030.00517.73
8.1.280.0140.01025.92
8.1.270.0060.00322.16
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0060.00617.33
8.1.230.0040.00822.51
8.1.220.0040.00417.74
8.1.210.0080.00018.77
8.1.200.0000.00917.36
8.1.190.0060.00317.35
8.1.180.0000.00718.10
8.1.170.0050.00718.52
8.1.160.0000.00822.08
8.1.150.0030.00519.00
8.1.140.0000.00817.51
8.1.130.0070.00017.86
8.1.120.0000.00817.52
8.1.110.0000.00917.46
8.1.100.0040.00417.43
8.1.90.0040.00417.45
8.1.80.0040.00417.50
8.1.70.0000.00717.40
8.1.60.0040.00417.59
8.1.50.0050.00317.57
8.1.40.0110.00017.61
8.1.30.0080.00017.68
8.1.20.0080.00017.73
8.1.10.0040.00417.53
8.1.00.0040.00417.52
8.0.300.0070.00019.09
8.0.290.0040.00416.75
8.0.280.0040.00418.51
8.0.270.0000.00817.26
8.0.260.0040.00418.55
8.0.250.0040.00417.03
8.0.240.0070.00017.07
8.0.230.0030.00316.99
8.0.220.0030.00516.91
8.0.210.0030.00316.85
8.0.200.0040.00417.00
8.0.190.0060.00316.95
8.0.180.0000.00816.90
8.0.170.0000.00716.95
8.0.160.0040.00416.97
8.0.150.0050.00216.96
8.0.140.0040.00416.80
8.0.130.0060.00013.38
8.0.120.0040.00416.95
8.0.110.0040.00416.96
8.0.100.0070.00016.99
8.0.90.0030.00516.83
8.0.80.0040.01116.99
8.0.70.0000.00816.82
8.0.60.0050.00316.93
8.0.50.0000.00816.86
8.0.30.0100.01317.08
8.0.20.0110.01117.40
8.0.10.0050.00216.93
8.0.00.0050.01316.95
7.4.330.0030.00315.09
7.4.320.0000.00616.55
7.4.300.0040.00416.68
7.4.290.0000.00816.57
7.4.280.0000.00816.58
7.4.270.0030.00316.48
7.4.260.0000.00716.56
7.4.250.0030.00516.45
7.4.240.0040.00416.55
7.4.230.0000.00716.73
7.4.220.0030.01716.47
7.4.210.0090.00616.38
7.4.200.0040.00416.60
7.4.160.0100.00716.41
7.4.150.0090.01317.40
7.4.140.0100.00817.86
7.4.130.0080.01016.42
7.4.120.0100.00716.53
7.4.110.0100.00716.54
7.4.100.0160.00916.48
7.4.90.0140.00416.51
7.4.80.0090.00916.50
7.4.70.0170.00716.52
7.4.60.0130.00516.48
7.4.50.0040.00416.31
7.4.40.0130.00316.47
7.4.30.0100.00616.50
7.4.10.0080.00914.82
7.4.00.0050.01214.99
7.3.330.0000.00613.16
7.3.320.0030.00313.26
7.3.310.0080.00016.18
7.3.300.0040.00416.26
7.3.290.0060.00916.26
7.3.280.0090.00716.28
7.3.270.0100.00717.40
7.3.260.0110.00716.76
7.3.250.0120.00516.38
7.3.240.0060.01516.33
7.3.230.0170.00016.46
7.3.210.0110.00716.61
7.3.200.0090.00919.39
7.3.190.0150.00816.37
7.3.180.0070.01016.29
7.3.170.0060.01516.31
7.3.160.0100.00616.29
7.3.130.0090.00814.98
7.3.120.0110.00314.75
7.3.110.0100.00714.83
7.3.100.0080.00714.72
7.3.90.0040.00814.87
7.3.80.0060.00614.70
7.3.70.0070.00314.79
7.3.60.0060.00914.83
7.3.50.0070.00914.78
7.3.40.0070.00714.75
7.3.30.0070.00714.73
7.3.20.0090.00516.55
7.3.10.0060.00716.55
7.3.00.0040.01016.64
7.2.330.0100.01316.47
7.2.320.0060.01016.57
7.2.310.0110.00716.43
7.2.300.0110.00716.54
7.2.290.0030.02016.77
7.2.260.0080.01115.05
7.2.250.0060.01214.98
7.2.240.0070.00714.90
7.2.230.0060.00914.98
7.2.220.0060.00915.12
7.2.210.0080.00715.06
7.2.200.0050.00815.01
7.2.190.0040.01215.01
7.2.180.0030.00714.98
7.2.170.0040.01015.05
7.2.160.0060.00914.96
7.2.150.0050.00816.75
7.2.140.0050.00916.64
7.2.130.0050.00916.75
7.2.120.0040.01216.75
7.2.110.0060.01016.75
7.2.100.0060.00616.74
7.2.90.0080.00716.79
7.2.80.0060.00716.79
7.2.70.0060.00816.57
7.2.60.0050.00916.86
7.2.50.0080.00616.68
7.2.40.0060.00816.75
7.2.30.0070.00616.89
7.2.20.0050.01016.74
7.2.10.0050.00916.72
7.2.00.0060.00917.19
7.1.330.0030.01115.66
7.1.320.0100.00415.62
7.1.310.0080.00315.56
7.1.300.0080.00815.56
7.1.290.0040.00815.69
7.1.280.0030.00815.54
7.1.270.0080.00615.64
7.1.260.0060.00715.58
7.1.250.0050.00815.68
7.1.240.0040.00915.71
7.1.230.0040.01015.50
7.1.220.0080.00615.59
7.1.210.0070.00515.63
7.1.200.0050.00715.44
7.1.190.0040.00715.63
7.1.180.0040.00815.73
7.1.170.0080.00615.50
7.1.160.0060.00715.66
7.1.150.0060.00715.66
7.1.140.0080.00415.64
7.1.130.0040.00815.67
7.1.120.0040.00815.59
7.1.110.0020.00915.73
7.1.100.0060.00616.17
7.1.90.0040.00715.67
7.1.80.0050.00815.62
7.1.70.0020.01015.96
7.1.60.0090.00716.35
7.1.50.0080.00815.95
7.1.40.0040.00915.63
7.1.30.0040.00915.65
7.1.20.0050.00815.61
7.1.10.0080.00615.53
7.1.00.0040.02416.94
7.0.330.0010.01315.32
7.0.320.0070.00415.29
7.0.310.0050.00515.31
7.0.300.0060.00715.18
7.0.290.0040.00815.28
7.0.280.0070.00615.23
7.0.270.0050.00815.24
7.0.260.0060.00615.31
7.0.250.0020.00915.28
7.0.240.0050.00815.51
7.0.230.0040.00615.34
7.0.220.0040.00715.40
7.0.210.0040.00815.49
7.0.200.0050.00715.51
7.0.190.0050.00815.35
7.0.180.0040.00715.48
7.0.170.0030.00915.38
7.0.160.0040.00715.41
7.0.150.0070.00615.34
7.0.140.0060.02116.78
7.0.130.0060.00715.40
7.0.120.0050.00615.38
7.0.110.0010.01115.30
7.0.100.0050.00715.27
7.0.90.0150.02416.33
7.0.80.0160.01916.32
7.0.70.0060.02416.24
7.0.60.0180.01916.16
7.0.50.0140.02116.25
7.0.40.0040.01614.88
7.0.30.0080.01214.85
7.0.20.0080.02014.93
7.0.10.0050.01714.89
7.0.00.0090.02314.79
5.6.400.0060.00614.21
5.6.390.0050.00814.35
5.6.380.0050.00914.33
5.6.370.0040.00814.19
5.6.360.0060.00714.22
5.6.350.0040.00614.24
5.6.340.0080.00614.32
5.6.330.0060.00614.39
5.6.320.0040.00914.33
5.6.310.0050.00614.18
5.6.300.0050.00914.19
5.6.290.0050.00814.22
5.6.280.0040.02215.60
5.6.270.0080.00814.29
5.6.260.0070.00614.43
5.6.250.0060.00814.36
5.6.240.0070.00814.24
5.6.230.0060.01915.68
5.6.220.0040.01915.48
5.6.210.0040.02415.50
5.6.200.0050.02515.67
5.6.190.0060.01715.68
5.6.180.0030.02515.60
5.6.170.0080.02215.50
5.6.160.0040.01815.51
5.6.150.0050.01315.56
5.6.140.0040.02515.73
5.6.130.0090.01815.70
5.6.120.0080.02115.48
5.6.110.0080.01615.60
5.6.100.0070.02115.53
5.6.90.0020.02315.56
5.6.80.0080.02115.44
5.6.70.0040.01815.51
5.6.60.0040.02415.42
5.6.50.0090.01215.32
5.6.40.0050.01415.34
5.6.30.0050.01515.40
5.6.20.0040.01615.49
5.6.10.0060.01515.46
5.6.00.0040.02415.45
5.5.380.0060.00814.18
5.5.370.0060.02015.49
5.5.360.0060.02415.36
5.5.350.0060.02215.42
5.5.340.0050.01915.48
5.5.330.0070.02215.46
5.5.320.0060.01515.41
5.5.310.0070.01915.57
5.5.300.0050.02415.43
5.5.290.0040.02315.54
5.5.280.0090.01515.42
5.5.270.0070.02015.48
5.5.260.0060.02315.42
5.5.250.0050.02315.44
5.5.240.0060.02215.43
5.5.230.0060.02115.34
5.5.220.0040.01715.27
5.5.210.0090.01315.25
5.5.200.0060.01915.36
5.5.190.0040.01515.32
5.5.180.0030.02715.33
5.5.170.0050.00814.20
5.5.160.0070.02115.43
5.5.150.0050.01715.18
5.5.140.0030.02515.24
5.5.130.0040.01715.26
5.5.120.0040.01615.31
5.5.110.0060.02315.37
5.5.100.0050.01815.41
5.5.90.0070.02115.35
5.5.80.0040.01715.41
5.5.70.0080.01715.28
5.5.60.0070.02415.18
5.5.50.0060.01215.25
5.5.40.0040.01615.27
5.5.30.0030.01715.24
5.5.20.0060.01815.21
5.5.10.0100.01415.24
5.5.00.0080.01915.30
5.4.450.0030.01813.24
5.4.440.0040.02313.29
5.4.430.0050.02013.11
5.4.420.0050.01913.20
5.4.410.0040.01413.23
5.4.400.0040.01113.21
5.4.390.0060.01213.03
5.4.380.0050.01413.12
5.4.370.0050.01313.13
5.4.360.0080.01113.04
5.4.350.0030.01813.14
5.4.340.0030.01113.21
5.4.330.0040.00811.73
5.4.320.0080.01513.21
5.4.310.0080.01013.18
5.4.300.0040.02013.22
5.4.290.0040.01612.99
5.4.280.0050.01512.92
5.4.270.0060.01713.18
5.4.260.0050.02113.14
5.4.250.0060.01413.11
5.4.240.0070.01813.07
5.4.230.0070.01413.07
5.4.220.0010.01813.24
5.4.210.0030.01713.09
5.4.200.0070.01713.16
5.4.190.0060.01213.05
5.4.180.0060.01513.17
5.4.170.0030.01413.16
5.4.160.0060.01213.11
5.4.150.0050.02013.09
5.4.140.0050.01812.59
5.4.130.0080.01312.55
5.4.120.0030.01412.59
5.4.110.0040.01512.65
5.4.100.0020.02012.66
5.4.90.0060.01312.68
5.4.80.0050.01112.58
5.4.70.0050.01012.54
5.4.60.0050.01212.64
5.4.50.0040.01212.67
5.4.40.0030.01312.61
5.4.30.0070.00712.62
5.4.20.0030.01212.68
5.4.10.0050.01112.58
5.4.00.0060.01112.57
5.3.290.0100.03714.68
5.3.280.0030.06014.59
5.3.270.0030.04014.65
5.3.260.0070.03714.71
5.3.250.0130.05714.64
5.3.240.0070.07314.71
5.3.230.0100.05714.64
5.3.220.0070.07714.75
5.3.210.0100.07314.54
5.3.200.0000.04314.75
5.3.190.0030.03714.53
5.3.180.0000.04014.61
5.3.170.0000.05014.58
5.3.160.0030.04014.67
5.3.150.0100.03014.75
5.3.140.0000.04014.55
5.3.130.0030.03014.65
5.3.120.0000.04014.65
5.3.110.0000.04314.59
5.3.100.0000.04014.05
5.3.90.0070.03314.15
5.3.80.0070.03313.99
5.3.70.0070.03314.10
5.3.60.0070.06714.14
5.3.50.0030.05013.89
5.3.40.0030.03714.11
5.3.30.0000.03713.86
5.3.20.0000.04013.80
5.3.10.0030.03713.68
5.3.00.0030.03713.67
5.2.170.0000.04711.19
5.2.160.0030.03311.11
5.2.150.0030.02711.32
5.2.140.0000.03311.23
5.2.130.0070.04011.02
5.2.120.0030.05711.08
5.2.110.0030.04711.22
5.2.100.0070.02311.18
5.2.90.0000.03011.28
5.2.80.0000.03011.21
5.2.70.0030.02311.24
5.2.60.0070.03311.12
5.2.50.0030.05711.12
5.2.40.0030.02310.91
5.2.30.0030.02711.15
5.2.20.0030.02311.08
5.2.10.0000.03010.96
5.2.00.0000.02710.91
5.1.60.0030.02010.59
5.1.50.0000.02710.59
5.1.40.0030.02310.59
5.1.30.0000.02710.59
5.1.20.0000.02710.59
5.1.10.0000.02710.59
5.1.00.0000.02310.59
5.0.50.0000.02010.59
5.0.40.0000.01710.59
5.0.30.0000.03010.59
5.0.20.0000.02010.59
5.0.10.0000.02010.59
5.0.00.0000.02710.59
4.4.90.0030.01310.59
4.4.80.0030.01710.59
4.4.70.0000.02010.59
4.4.60.0000.02310.59
4.4.50.0030.01310.59
4.4.40.0030.02010.59
4.4.30.0030.01310.59
4.4.20.0030.01710.59
4.4.10.0030.03310.59
4.4.00.0000.02310.59
4.3.110.0030.02710.59
4.3.100.0070.00710.59
4.3.90.0030.01310.59
4.3.80.0070.01310.59
4.3.70.0000.01310.59
4.3.60.0000.01310.59
4.3.50.0000.01710.59
4.3.40.0030.02310.59
4.3.30.0000.01710.59
4.3.20.0000.02010.59
4.3.10.0000.01710.59
4.3.00.0000.01310.59

preferences:
42.81 ms | 400 KiB | 5 Q