3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Class to access the functionality of the HTML to docx converter */ // Load the files we need: require_once 'phpword/PHPWord.php'; require_once 'simplehtmldom/simple_html_dom.php'; require_once 'htmltodocx_converter/h2d_htmlconverter.php'; require_once 'example_files/styles.inc'; /// Initiate the class class HtmlToDocx{ public $base_path; public $base_root; public $html; public $html_array; public $PHPWord; /// __construct public function __contruct(){ $a=func_get_args(); $i=func_num_args(); if(method_exists($this,$f='__construct'.$i)){ call_user_func_array(array($this,$f),$a); }} /// __construct0 public function __contruct0(){ $base_path=substr($_SERVER['PHP_SELF'],0,((strrpos($_SERVER['PHP_SELF'],'/'))+1)); $base_root="http://".$_SERVER['HTTP_HOST']; $this->process(); } /// __construct1 public function __contruct1($base_path){ $base_root="http://".$_SERVER['HTTP_HOST']; $this->process(); } /// __construct2 public function __contruct2($base_path,$base_root){ $this->process($base_path,$base_root); } public function process($base_path,$base_root){ // Create a new PHPWord Object $PHPWord=new PHPWord(); // Every element you want to append to the word document is placed in a section. So you need a section: $section=$PHPWord->createSection(); $this->base_path=$base_path; $this->base_root=$base_root; // Provide some initial settings: $initial_state=array( // Required parameters: 'phpword_object'=>&$PHPWord, // Must be passed by reference. 'base_root'=>$base_root, // Required for link elements - change it to your domain. 'base_path'=>$base_path, // Path from base_root to whatever url your links are relative to. // Optional parameters - showing the defaults if you don't set anything: 'current_style'=>array('size'=>'11'), // The PHPWord style on the top element - may be inherited by descendent elements. 'parents'=>array(0=>'body'), // Our parent is body. 'list_depth'=>0, // This is the current depth of any current list. 'context'=>'section', // Possible values - section, footer or header. 'pseudo_list'=>TRUE, // NOTE: Word lists not yet supported (TRUE is the only option at present). 'pseudo_list_indicator_font_name'=>'Wingdings', // Bullet indicator font. 'pseudo_list_indicator_font_size'=>'7', // Bullet indicator size. 'pseudo_list_indicator_character'=>'l ', // Gives a circle bullet point with wingdings. 'table_allowed'=>TRUE, // Note, if you are adding this html into a PHPWord table you should set this to FALSE: tables cannot be nested in PHPWord. 'treat_div_as_paragraph'=>TRUE, // If set to TRUE, each new div will trigger a new line in the Word document. // Optional - no default: 'style_sheet'=>htmltodocx_styles_example() // This is an array (the "style sheet") - returned by htmltodocx_styles_example() here (in styles.inc) - see this function for an example of how to construct this array. ); // Create a DOM object $this->html=new simple_html_dom(); } /// input_string public function input_string(&$input_string){ $html=$this->html; // Load HTML from a string load_string:{ $html->load($input_string); // Create the dom array of elements which we are going to work on: $html_array=$html->find('body'); if(empty($html_array)){ $input_string="<body>".$input_string."</body>"; goto load_string; }}} /// input_file public function input_file($input_file){ $html=$this->html; // Load HTML from a URL or a HTML file $html->load_file($input_file); // Create the dom array of elements which we are going to work on: load_file:{ $html_array=$html->find('body'); if(empty($html_array)){ $html->outertext="<body>".$html->outertext."</body>"; goto load_file; }}} /// output_file public function output_file(array $output_file){ $html=$this->html; $base_output_file=array(tempnam(sys_get_temp_dir(),'htd')); array_merge($base_output_file,$output_file); // Convert the HTML and put it into the PHPWord object htmltodocx_insert_html($section,$html_array[0]->nodes,$initial_state); // At least write the document to webspace: $objWriter=PHPWord_IOFactory::createWriter($PHPWord,'Word2007'); $objWriter->save($output_file); } /// save_file public function save_file(){ // Download the file: header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.$output_file); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: '.filesize($output_file)); } /// close public function close(){ // Clear the HTML dom object: $this->html->clear(); unset($this->html); $this->base_path=null; unset($this->base_path); $this->base_root=null; unset($this->base_root); unset($this); ob_clean(); flush(); gc_collect_cycles(); } /// delete_file public function delete_file(){ unlink($output_file); } /// __destruct public function __destruct(){ $this->close(); }} ?>

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.0110.01118.22
8.3.50.0090.00921.82
8.3.40.0090.00618.84
8.3.30.0100.00319.10
8.3.20.0000.01020.34
8.3.10.0040.00421.87
8.3.00.0040.00422.40
8.2.180.0040.01916.75
8.2.170.0110.00722.96
8.2.160.0180.00020.43
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0090.00026.16
8.2.120.0040.00419.70
8.2.110.0060.00322.22
8.2.100.0050.00519.45
8.2.90.0000.00819.21
8.2.80.0050.00319.64
8.2.70.0080.00317.50
8.2.60.0040.00417.93
8.2.50.0050.00518.07
8.2.40.0030.00518.22
8.2.30.0040.00418.01
8.2.20.0000.00717.68
8.2.10.0030.00517.69
8.2.00.0090.00317.77
8.1.280.0100.00725.92
8.1.270.0060.00322.23
8.1.260.0070.00426.35
8.1.250.0060.00328.09
8.1.240.0070.00323.97
8.1.230.0060.00619.13
8.1.220.0040.00417.74
8.1.210.0080.00018.77
8.1.200.0090.00017.22
8.1.190.0050.00317.27
8.1.180.0000.00818.10
8.1.170.0040.00418.56
8.1.160.0080.00021.95
8.1.150.0040.00418.52
8.1.140.0040.00417.41
8.1.130.0000.00717.78
8.1.120.0040.00417.34
8.1.110.0040.00417.35
8.1.100.0040.00417.35
8.1.90.0040.00417.43
8.1.80.0040.00417.29
8.1.70.0040.00417.45
8.1.60.0040.00417.60
8.1.50.0000.00817.49
8.1.40.0040.00417.54
8.1.30.0000.00817.57
8.1.20.0000.00817.65
8.1.10.0000.00817.55
8.1.00.0040.00417.34
8.0.300.0040.00418.77
8.0.290.0050.00217.18
8.0.280.0030.00318.45
8.0.270.0070.00017.23
8.0.260.0030.00716.89
8.0.250.0030.00316.95
8.0.240.0040.00417.03
8.0.230.0070.00016.95
8.0.220.0000.00716.80
8.0.210.0000.00716.82
8.0.200.0000.00616.86
8.0.190.0060.00317.00
8.0.180.0040.00416.89
8.0.170.0040.00416.83
8.0.160.0050.00316.89
8.0.150.0000.00816.91
8.0.140.0040.00416.92
8.0.130.0050.00013.33
8.0.120.0060.00215.07
8.0.110.0040.00415.04
8.0.100.0080.00215.13
8.0.90.0050.00515.10
8.0.80.0060.00715.14
8.0.70.0080.00215.07
8.0.60.0050.00515.11
8.0.50.0050.00515.19
8.0.30.0130.00615.77
8.0.20.0130.00616.08
8.0.10.0050.00515.13
8.0.00.0130.00215.64
7.4.330.0050.00015.00
7.4.320.0000.00616.60
7.4.300.0000.00716.49
7.4.290.0040.00716.39
7.4.280.0070.00016.48
7.4.270.0000.00716.59
7.4.260.0060.00316.49
7.4.250.0020.00514.93
7.4.240.0060.00315.45
7.4.230.0060.00414.86
7.4.220.0090.00814.89
7.4.210.0060.00915.70
7.4.200.0040.00614.95
7.4.190.0050.00514.94
7.4.180.0040.00813.25
7.4.160.0080.00614.86
7.4.150.0090.00615.33
7.4.140.0110.00716.33
7.4.130.0100.01015.42
7.4.120.0110.00615.35
7.4.110.0080.00614.78
7.4.100.0070.00714.83
7.4.90.0120.00314.80
7.4.80.0100.00716.27
7.4.70.0070.00714.79
7.4.60.0060.00714.77
7.4.50.0090.00114.70
7.4.40.0100.00517.90
7.4.30.0100.00314.87
7.4.20.0140.00013.08
7.4.10.0130.00013.12
7.4.00.0090.00514.04
7.3.330.0030.00313.16
7.3.320.0000.00613.29
7.3.310.0050.00414.80
7.3.300.0050.00614.67
7.3.290.0070.00714.78
7.3.280.0120.00715.60
7.3.270.0100.00615.36
7.3.260.0110.00414.84
7.3.250.0090.01015.27
7.3.240.0100.00714.80
7.3.230.0090.00814.90
7.3.220.0140.00013.13
7.3.210.0140.00214.70
7.3.200.0080.00916.30
7.3.190.0090.00414.80
7.3.180.0020.01114.83
7.3.170.0040.00714.77
7.3.160.0060.00614.75
7.3.150.0050.00213.10
7.3.140.0090.00013.08
7.3.130.0040.00413.27
7.3.120.0050.00614.11
7.3.110.0030.00313.05
7.3.100.0040.00412.96
7.3.90.0030.00613.29
7.3.80.0060.00313.05
7.3.70.0040.00313.21
7.3.60.0020.00413.30
7.3.50.0000.00713.10
7.3.40.0000.00613.34
7.3.30.0000.00713.19
7.3.20.0040.00415.13
7.3.10.0070.00014.97
7.3.00.0040.00414.89
7.2.340.0060.00013.26
7.2.330.0090.00614.87
7.2.320.0090.01014.81
7.2.310.0100.00514.81
7.2.300.0040.01114.63
7.2.290.0110.00614.82
7.2.280.0130.00013.20
7.2.270.0090.00413.20
7.2.260.0060.00612.95
7.2.250.0040.00813.04
7.2.240.0110.00313.15
7.2.230.0130.00013.26
7.2.220.0100.00313.14
7.2.210.0090.00313.16
7.2.200.0140.00013.38
7.2.190.0130.00013.13
7.2.180.0090.00413.30
7.2.170.0080.00413.38
7.2.160.0000.01213.38
7.2.150.0050.00914.95
7.2.140.0100.00315.11
7.2.130.0080.00515.35
7.2.120.0090.00415.16
7.2.110.0130.00015.14
7.2.100.0110.00315.21
7.2.90.0130.00014.95
7.2.80.0130.00015.14
7.2.70.0100.00314.98
7.2.60.0060.00815.79
7.2.50.0120.00015.19
7.2.40.0130.00015.03
7.2.30.0110.00215.00
7.2.20.0070.00714.98
7.2.10.0050.00915.18
7.2.00.0060.00817.05
7.1.330.0120.00014.17
7.1.320.0120.00014.16
7.1.310.0080.00414.16
7.1.300.0120.00014.14
7.1.290.0050.00813.95
7.1.280.0120.00014.00
7.1.270.0060.00614.12
7.1.260.0060.00614.18
7.1.250.0060.00614.08
7.1.240.0120.00014.08
7.1.230.0060.00614.13
7.1.220.0040.00913.99
7.1.210.0100.00313.95
7.1.200.0110.00214.78
7.1.190.0110.00314.09
7.1.180.0120.00014.11
7.1.170.0130.00014.15
7.1.160.0120.00013.85
7.1.150.0120.00013.96
7.1.140.0100.00314.06
7.1.130.0070.00613.85
7.1.120.0080.00414.03
7.1.110.0040.00913.84
7.1.100.0070.00415.77
7.1.90.0090.00414.11
7.1.80.0090.00314.02
7.1.70.0060.00315.25
7.1.60.0070.01216.86
7.1.50.0040.00915.38
7.1.40.0120.00014.10
7.1.30.0100.00214.04
7.1.20.0080.00513.98
7.1.10.0120.00014.06
7.1.00.0080.03818.25
7.0.330.0070.00613.88
7.0.320.0140.00014.09
7.0.310.0120.00013.91
7.0.300.0060.00613.91
7.0.290.0060.00614.05
7.0.280.0090.00314.01
7.0.270.0120.00014.01
7.0.260.0080.00413.96
7.0.250.0090.00314.13
7.0.240.0080.00413.96
7.0.230.0120.00014.05
7.0.220.0080.00413.99
7.0.210.0100.00214.09
7.0.200.0030.00715.30
7.0.190.0090.00414.07
7.0.180.0100.00313.88
7.0.170.0070.00513.91
7.0.160.0130.00013.97
7.0.150.0090.00313.87
7.0.140.0060.03818.00
7.0.130.0130.00013.99
7.0.120.0070.00514.09
7.0.110.0060.00613.99
7.0.100.0120.00014.05
7.0.90.0000.01213.80
7.0.80.0250.03616.97
7.0.70.0270.02516.93
7.0.60.0350.04016.86
7.0.50.0340.02417.05
7.0.40.0110.04216.96
7.0.30.0140.03717.06
7.0.20.0080.02616.96
7.0.10.0160.03217.03
7.0.00.0080.04117.02
5.6.400.0070.00512.71
5.6.390.0120.00012.38
5.6.380.0120.00012.58
5.6.370.0090.00312.41
5.6.360.0040.00812.36
5.6.350.0090.00312.58
5.6.340.0000.01312.73
5.6.330.0070.00412.41
5.6.320.0120.00012.44
5.6.310.0060.00612.59
5.6.300.0090.00312.56
5.6.290.0080.00412.44
5.6.280.0080.03616.84
5.6.270.0040.00712.54
5.6.260.0050.00512.65
5.6.250.0070.00412.50
5.6.240.0110.00012.73
5.6.230.0070.04416.64
5.6.220.0090.03516.69
5.6.210.0120.03216.71
5.6.200.0130.03816.97
5.6.190.0110.03616.79
5.6.180.0120.03216.88
5.6.170.0120.03916.74
5.6.160.0050.02516.91
5.6.150.0090.04417.00
5.6.140.0090.02816.74
5.6.130.0040.04716.83
5.6.120.0100.03216.72
5.6.110.0090.02616.76
5.6.100.0140.03516.77
5.6.90.0090.03816.79
5.6.80.0090.04016.52
5.6.70.0080.04116.57
5.6.60.0030.03016.48
5.6.50.0090.04216.63
5.6.40.0090.04016.45
5.6.30.0060.02316.52
5.6.20.0020.04516.48
5.6.10.0030.02516.58
5.6.00.0090.02816.33
5.5.380.0040.00712.42
5.5.370.0110.01916.52
5.5.360.0130.03616.38
5.5.350.0070.02216.35
5.5.340.0070.03816.54
5.5.330.0050.03716.64
5.5.320.0120.03816.69
5.5.310.0070.04316.75
5.5.300.0060.02716.52
5.5.290.0110.02216.54
5.5.280.0150.03916.62
5.5.270.0100.04316.56
5.5.260.0110.04216.62
5.5.250.0090.04216.68
5.5.240.0060.04116.40
5.5.230.0090.04016.35
5.5.220.0090.02316.36
5.5.210.0060.02116.42
5.5.200.0090.02716.35
5.5.190.0100.03016.14
5.5.180.0090.03316.21
5.5.170.0060.00612.42
5.5.160.0070.04216.17
5.5.150.0120.03716.17
5.5.140.0080.03116.27
5.5.130.0060.03616.24
5.5.120.0060.03616.34
5.5.110.0090.03316.27
5.5.100.0090.02516.36
5.5.90.0080.04016.41
5.5.80.0100.03316.22
5.5.70.0080.03816.29
5.5.60.0040.02616.21
5.5.50.0020.04316.35
5.5.40.0070.03916.28
5.5.30.0040.02816.38
5.5.20.0100.02216.24
5.5.10.0150.03216.10
5.5.00.0070.04416.24
5.4.450.0110.01815.96
5.4.440.0090.02516.07
5.4.430.0120.03816.11
5.4.420.0050.03015.85
5.4.410.0090.03315.87
5.4.400.0080.04015.69
5.4.390.0110.03815.77
5.4.380.0040.02515.90
5.4.370.0080.02515.80
5.4.360.0070.04015.83
5.4.350.0100.03015.75
5.4.340.0100.03915.79
5.4.330.0050.00512.57
5.4.320.0070.02115.76
5.4.310.0110.03515.69
5.4.300.0070.03815.67
5.4.290.0040.03915.78
5.4.280.0090.04115.81
5.4.270.0090.03915.94
5.4.260.0070.03915.73
5.4.250.0070.02315.70
5.4.240.0060.02715.90
5.4.230.0060.02315.68
5.4.220.0060.02115.75
5.4.210.0090.03815.61
5.4.200.0060.04115.71
5.4.190.0040.03215.59
5.4.180.0060.04415.74
5.4.170.0070.03315.79
5.4.160.0070.04015.54
5.4.150.0090.02715.73
5.4.140.0070.03314.33
5.4.130.0030.02714.57
5.4.120.0090.02414.48
5.4.110.0030.03714.55
5.4.100.0050.02814.59
5.4.90.0100.03714.60
5.4.80.0040.02114.62
5.4.70.0080.02714.42
5.4.60.0050.02814.53
5.4.50.0070.03114.36
5.4.40.0050.02814.42
5.4.30.0120.02214.54
5.4.20.0080.03514.35
5.4.10.0080.02814.49
5.4.00.0090.02014.13
5.3.290.0160.03513.74
5.3.280.0070.04213.65
5.3.270.0130.03513.75
5.3.260.0080.03213.79
5.3.250.0080.03613.69
5.3.240.0060.04113.79
5.3.230.0090.03613.76
5.3.220.0110.01913.75
5.3.210.0090.04013.79
5.3.200.0080.02913.66
5.3.190.0060.02113.81
5.3.180.0080.01913.87
5.3.170.0080.03813.73
5.3.160.0090.03813.85
5.3.150.0030.03013.89
5.3.140.0050.02713.85
5.3.130.0070.02313.66
5.3.120.0040.02713.80
5.3.110.0060.04313.62
5.3.100.0060.03913.45
5.3.90.0100.02813.51
5.3.80.0100.03713.56
5.3.70.0040.02913.40
5.3.60.0020.03713.58
5.3.50.0070.03513.46
5.3.40.0070.02213.32
5.3.30.0040.04113.28
5.3.20.0060.04013.27
5.3.10.0070.03913.31
5.3.00.0060.03913.14
5.2.170.0020.02311.79
5.2.160.0060.03111.78
5.2.150.0020.03611.66
5.2.140.0080.01711.76
5.2.130.0090.03011.76
5.2.120.0060.03211.71
5.2.110.0070.03211.63
5.2.100.0100.02211.76
5.2.90.0050.02811.65
5.2.80.0020.03311.74
5.2.70.0040.03411.72
5.2.60.0070.01611.53
5.2.50.0080.03111.67
5.2.40.0020.03711.60
5.2.30.0070.02711.71
5.2.20.0080.03011.66
5.2.10.0040.03211.49
5.2.00.0090.02711.53
5.1.60.0040.02811.16
5.1.50.0050.02711.15
5.1.40.0050.01811.21
5.1.30.0020.03411.41
5.1.20.0070.02711.33
5.1.10.0060.02211.33
5.1.00.0080.01411.09
5.0.50.0030.02511.03
5.0.40.0070.02011.03
5.0.30.0020.03011.03
5.0.20.0030.02511.03
5.0.10.0020.02011.03
5.0.00.0030.03511.03
4.4.90.0030.01011.03
4.4.80.0020.01811.03
4.4.70.0020.02011.03
4.4.60.0040.01311.03
4.4.50.0030.01811.03
4.4.40.0000.02011.03
4.4.30.0030.01211.03
4.4.20.0040.01811.03
4.4.10.0030.01011.03
4.4.00.0020.02911.03
4.3.110.0020.01811.03
4.3.100.0020.01811.03
4.3.90.0000.01911.03
4.3.80.0020.01811.03
4.3.70.0030.01711.03
4.3.60.0070.01311.03
4.3.50.0020.01011.03
4.3.40.0000.02911.03
4.3.30.0000.01311.03
4.3.20.0050.01011.03
4.3.10.0020.01311.03
4.3.00.0010.01711.03

preferences:
46.99 ms | 400 KiB | 5 Q