3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Strip the HTML of Word documents * * @author rene.veldink * @author christoph.roensch */ class Hgs_Filter_StripWordHtml #implements Zend_Filter_Interface { /** * @var string */ /*const ALLOW_DEFAULT = '<b><i><sup><sub><em><strong><u><br><ol><li><ul><span><div><h1><h2><h3><p>';*/ /** * @var string */ protected $_allow = '<b><i><sup><sub><em><strong><u><br><ol><li><ul><span><div><h1><h2><h3><p>'; /** * Constructor * * @param array|string $options * @return void */ public function __construct($options = array()) { if (is_string($options)) { $this->_allow = $options; } if (isset($options['allow'])) { $this->_allow = $options['allow']; } } /** * @param string $value * @return string */ public function filter($value) { return $this->strip_word_html($value, $this->_allow); } /** * - moved $allow default value to class property * - fixed regex for 'simplify style tags', <br> were replaced with <b> * - fixed bad escape sequence near $num_matches * @link http://php.net/manual/de/function.strip-tags.php#99643 */ private function strip_word_html($text, $allowed_tags /*= self::ALLOW_DEFAULT*/) { echo "Debug: $this->_allow\n"; mb_regex_encoding('UTF-8'); //replace MS special characters first $search = array('/&lsquo;/u', '/&rsquo;/u', '/&ldquo;/u', '/&rdquo;/u', '/&mdash;/u'); $replace = array('\'', '\'', '"', '"', '-'); $text = preg_replace($search, $replace, $text); //make sure _all_ html entities are converted to the plain ascii equivalents - it appears //in some MS headers, some html entities are encoded and some aren't $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); //try to strip out any C style comments first, since these, embedded in html comments, seem to //prevent strip_tags from removing html comments (MS Word introduced combination) if(mb_stripos($text, '/*') !== FALSE){ $text = mb_eregi_replace('#/\*.*?\*/#s', '', $text, 'm'); } //introduce a space into any arithmetic expressions that could be caught by strip_tags so that they won't be //'<1' becomes '< 1'(note: somewhat application specific) $text = preg_replace(array('/<([0-9]+)/'), array('< $1'), $text); $text = strip_tags($text, $allowed_tags); //eliminate extraneous whitespace from start and end of line, or anywhere there are two or more spaces, convert it to one $text = preg_replace(array('/^\s\s+/', '/\s\s+$/', '/\s\s+/u'), array('', '', ' '), $text); //strip out inline css and simplify style tags $search = array('#<(strong|b)\s+[^>]*>(.*?)</(strong|b)>#isu', '#<(em|i)[^>]*>(.*?)</(em|i)>#isu', '#<u[^>]*>(.*?)</u>#isu'); $replace = array('<b>$2</b>', '<i>$2</i>', '<u>$1</u>'); $text = preg_replace($search, $replace, $text); //on some of the ?newer MS Word exports, where you get conditionals of the form 'if gte mso 9', etc., it appears //that whatever is in one of the html comments prevents strip_tags from eradicating the html comment that contains //some MS Style Definitions - this last bit gets rid of any leftover comments $num_matches = preg_match_all('/\<!--/u', $text, $matches); if ($num_matches) { $text = preg_replace('/\<!--(.)*--\>/isu', '', $text); } return $text; } } $a = "<p>Hey<br /><b>Ho</b>,<i>Lets Go!</i></p><ol><li>1</li></ol><ul><li>2</li></ul>"; $filter = new Hgs_Filter_StripWordHtml(Hgs_Filter_StripWordHtml::ALLOW_DEFAULT); $b = $filter->filter($a); var_dump($a == $b); echo "\n$b";

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.40.0120.00318.94
8.3.30.0110.00720.38
8.3.20.0050.00320.16
8.3.10.0040.00422.15
8.3.00.0030.00522.45
8.2.170.0090.00922.96
8.2.160.0040.01120.22
8.2.150.0080.00024.18
8.2.140.0090.00024.66
8.2.130.0040.00426.16
8.2.120.0080.00019.66
8.2.110.0140.00322.21
8.2.100.0030.00919.21
8.2.90.0050.00319.02
8.2.80.0000.00819.28
8.2.70.0030.00617.50
8.2.60.0000.00818.04
8.2.50.0050.00318.07
8.2.40.0080.00018.16
8.2.30.0040.00418.11
8.2.20.0040.00417.76
8.2.10.0050.00317.81
8.2.00.0030.00617.86
8.1.270.0040.00424.66
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0000.00923.87
8.1.230.0110.00018.98
8.1.220.0000.00817.78
8.1.210.0040.00418.77
8.1.200.0060.00317.48
8.1.190.0080.00017.63
8.1.180.0060.00319.13
8.1.170.0050.00318.43
8.1.160.0000.00722.19
8.1.150.0000.00818.68
8.1.140.0050.00317.43
8.1.130.0000.00817.86
8.1.120.0050.00317.55
8.1.110.0040.00417.39
8.1.100.0040.00417.49
8.1.90.0000.00717.55
8.1.80.0040.00417.39
8.1.70.0000.00717.54
8.1.60.0070.00017.66
8.1.50.0050.00317.60
8.1.40.0070.00417.54
8.1.30.0020.00517.57
8.1.20.0000.00917.65
8.1.10.0040.00417.53
8.1.00.0030.00617.59
8.0.300.0040.00718.77
8.0.290.0020.00517.29
8.0.280.0000.00718.46
8.0.270.0030.00317.30
8.0.260.0030.00316.86
8.0.250.0040.00417.13
8.0.240.0000.00817.08
8.0.230.0030.00316.92
8.0.220.0040.00416.98
8.0.210.0030.00316.86
8.0.200.0030.00317.00
8.0.190.0090.00016.96
8.0.180.0050.00216.98
8.0.170.0000.00817.04
8.0.160.0030.00316.99
8.0.150.0030.00316.95
8.0.140.0060.00316.90
8.0.130.0000.00613.44
8.0.120.0040.00416.87
8.0.110.0020.00516.90
8.0.100.0090.00017.06
8.0.90.0040.00416.95
8.0.80.0060.00917.03
8.0.70.0040.00416.94
8.0.60.0050.00216.85
8.0.50.0000.00717.05
8.0.30.0080.01317.16
8.0.20.0080.01017.40
8.0.10.0040.00417.00
8.0.00.0070.01116.85
7.4.330.0020.00215.00
7.4.320.0030.00316.61
7.4.300.0000.00616.63
7.4.290.0000.00716.48
7.4.280.0000.00716.55
7.4.270.0030.00516.70
7.4.260.0000.00716.64
7.4.250.0000.00816.43
7.4.240.0020.00516.58
7.4.230.0000.00816.71
7.4.220.0090.01216.76
7.4.210.0050.01216.62
7.4.200.0000.00716.64
7.4.190.0050.00216.69
7.4.160.0000.01816.54
7.4.150.0100.01417.40
7.4.140.0130.01117.86
7.4.130.0090.00916.65
7.4.120.0080.01116.60
7.4.110.0070.01616.48
7.4.100.0110.00816.43
7.4.90.0160.00616.70
7.4.80.0090.01219.39
7.4.70.0070.01016.78
7.4.60.0100.00716.29
7.4.50.0000.00716.38
7.4.40.0070.00722.77
7.4.30.0070.01416.64
7.4.00.0040.01215.05
7.3.330.0000.00513.24
7.3.320.0000.00513.18
7.3.310.0030.00316.43
7.3.300.0030.00316.33
7.3.290.0080.00516.43
7.3.280.0100.00816.40
7.3.270.0070.01317.40
7.3.260.0140.01016.56
7.3.250.0090.00816.53
7.3.240.0070.01316.66
7.3.230.0000.01616.39
7.3.210.0040.01216.42
7.3.200.0130.00519.39
7.3.190.0000.01616.55
7.3.180.0080.00816.41
7.3.170.0130.00416.47
7.3.160.0170.00016.49
7.3.120.0060.00914.98
7.2.330.0070.01016.71
7.2.320.0130.00616.41
7.2.310.0100.00616.66
7.2.300.0090.01116.39
7.2.290.0090.00716.61
7.2.60.0100.00716.68
7.2.00.0030.01419.05
7.1.200.0060.00615.57
7.1.100.0060.00618.02
7.1.70.0060.00316.92
7.1.60.0070.01319.43
7.1.50.0110.01416.94
7.1.00.0030.03322.57
7.0.200.0000.00716.77
7.0.140.0130.06022.15
7.0.60.0200.06320.07
7.0.50.0170.07017.90
7.0.40.0070.07020.24
7.0.30.0230.07720.14
7.0.20.0200.05320.20
7.0.10.0230.08020.15
7.0.00.0130.07720.18
5.6.280.0070.07021.09
5.6.210.0130.07320.79
5.6.200.0070.04318.29
5.6.190.0070.06720.50
5.6.180.2400.04720.33
5.6.170.0300.06720.48
5.6.160.0000.04720.54
5.6.150.0000.09018.15
5.6.140.0070.08718.17
5.6.130.0100.07318.27
5.6.120.0000.04321.17
5.6.110.0000.05321.01
5.6.100.0070.06721.01
5.6.90.0100.03320.89
5.6.80.0070.03720.55
5.6.70.4570.03720.50
5.5.350.0000.07720.32
5.5.340.0170.07018.05
5.5.330.0130.08020.27
5.5.320.0370.03320.35
5.5.310.0200.08020.19
5.5.300.0070.06318.02
5.5.290.0070.06017.91
5.5.280.0170.07720.92
5.5.270.0100.08320.81
5.5.260.0070.08720.79
5.5.250.0100.07320.80
5.5.240.0130.07720.17
5.4.450.0300.05019.52
5.4.440.0270.07319.37
5.4.430.0270.07319.41
5.4.420.0200.06719.47
5.4.410.0330.06019.27
5.4.400.0370.06319.00
5.4.390.0300.07019.07
5.4.380.0230.04018.98
5.4.370.0230.07019.00
5.4.360.0200.06719.16
5.4.350.0230.04719.05
5.4.340.0200.04719.01
5.4.320.0270.03018.99
5.4.310.0170.04719.16
5.4.300.0330.05319.07
5.4.290.0170.04018.98
5.4.280.0170.04319.15
5.4.270.0100.04019.24
5.4.260.0030.07319.04
5.4.250.0030.05319.23
5.4.240.0070.04319.04
5.4.230.0070.07019.15
5.4.220.0070.07018.98
5.4.210.0000.05018.95
5.4.200.0030.05319.06
5.4.190.0100.06719.34
5.4.180.0030.07718.86
5.4.170.0030.04319.30
5.4.160.0130.07319.13
5.4.150.0100.07319.07
5.4.140.0100.04716.33
5.4.130.0070.07016.46
5.4.120.0130.06716.36
5.4.110.0130.06316.31
5.4.100.0170.06316.20
5.4.90.0070.04316.54
5.4.80.0100.03316.45
5.4.70.0170.06716.44
5.4.60.0170.06316.26
5.4.50.0300.06016.44
5.4.40.0230.05016.39
5.4.30.0230.03316.26
5.4.20.0100.04316.25
5.4.10.0170.05016.44
5.4.00.0100.07715.83
5.3.290.0200.05014.84
5.3.280.0100.04314.58
5.3.270.0070.04714.52
5.3.260.0030.08014.74
5.3.250.0170.07014.77
5.3.240.0100.07714.70
5.3.230.0070.05314.58
5.3.220.0100.07014.49
5.3.210.0100.07314.50
5.3.200.0130.06714.80
5.3.190.0170.05714.80
5.3.180.0170.03714.48
5.3.170.0100.06714.74
5.3.160.0100.08014.50
5.3.150.0170.08014.62
5.3.140.0170.07314.54
5.3.130.0300.05314.56
5.3.120.0200.06314.47
5.3.110.0170.04014.71
5.3.100.0100.05313.95
5.3.90.0100.07713.94
5.3.80.0030.07714.04
5.3.70.0330.03313.95
5.3.60.0270.06714.13
5.3.50.0200.04714.13
5.3.40.0130.05013.97
5.3.30.0170.04313.84
5.3.20.0230.07013.64
5.3.10.0070.06013.75
5.3.00.0330.04713.58
5.2.170.0370.02712.67
5.2.160.0170.04312.67
5.2.150.0200.05312.67
5.2.140.0270.02712.67
5.2.130.0130.06012.67
5.2.120.0130.05712.67
5.2.110.0170.03712.67
5.2.100.0200.05712.67
5.2.90.0200.04312.67
5.2.80.0100.03012.67
5.2.70.0130.04012.67
5.2.60.0070.04312.67
5.2.50.0170.04012.67
5.2.40.0170.03312.67
5.2.30.0130.03712.67
5.2.20.0170.02312.67
5.2.10.0100.06712.67
5.2.00.0100.04312.67
5.1.60.0070.04012.67
5.1.50.0070.05312.67
5.1.40.0000.05312.67
5.1.30.0030.04012.67
5.1.20.0000.04712.67
5.1.10.0030.02712.67
5.1.00.0070.05312.67
5.0.50.0030.04712.67
5.0.40.0000.05012.67
5.0.30.0070.05312.67
5.0.20.0030.03312.67
5.0.10.0130.01312.67
5.0.00.0070.06012.67
4.4.90.0000.02712.67
4.4.80.0070.02012.67
4.4.70.0070.03312.67
4.4.60.0070.03012.67
4.4.50.0070.02312.67
4.4.40.0000.02712.67
4.4.30.0030.03712.67
4.4.20.0030.03012.67
4.4.10.0000.03312.67
4.4.00.0000.03712.67
4.3.110.0000.03312.67
4.3.100.0030.01712.67
4.3.90.0170.01312.67
4.3.80.0070.03712.67
4.3.70.0000.02012.67
4.3.60.0070.03312.67
4.3.50.0000.01712.67
4.3.40.0070.02712.67
4.3.30.0000.01712.67
4.3.20.0000.03312.67
4.3.10.0000.01712.67
4.3.00.0000.03712.67

preferences:
89.56 ms | 400 KiB | 5 Q