3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Filename { /** * @var string */ private $basename; /** * @var string */ private $extension; /** * Filename constructor. * * @param string $filename * @param array $replace */ public function __construct(string $filename, array $replace = []) { $info = pathinfo($filename); $info = array_map('strtolower', $info); if (array_key_exists('extension', $info)) { $this->setExtension($info['extension']); } if (empty($replace)) { $replace = [ ' ' => '_', 'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue', 'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'ß' => 'ss' ]; } $this->basename = self::clean($info['filename'], $replace); } /** * @param int $length * * @throws \Exception */ public function limitLength(int $length) { assure($length > 0, 'Invalide Länge: %d', $length); if (strlen($this->basename) > $length) { $this->basename = substr($this->basename, 0, $length); } } /** * @param string $str * @param array $replace * * @return string */ public static function clean(string $str, array $replace = []): string { $str = trim($str); $str = trim($str, '_-'); if (!empty($replace)) { $str = str_replace(array_keys($replace), array_values($replace), $str); } $str = preg_replace('#[^\w\-]+#i', '_', $str); //Mehrere aufeinanderfolgende Unterstriche zu einem Unterstrich $str = preg_replace('#_+#', '_', $str); //Bindestrich vor Unterstrich zum Bindestrich $str = preg_replace('#\-_#', '-', $str); //Bindestrich nach Unterstrich zum Bindestrich $str = preg_replace('#_\-#', '-', $str); //Unterstrich am Ende zu nix $str = preg_replace('#_$#', '', $str); return $str; } /** * @return null|string */ public function getExtension() { return $this->extension; } /** * @return bool */ public function hasExtension(): bool { return $this->extension !== null; } /** * @param string $extension */ public function setExtension(string $extension) { if (MimeTypes::isExtensionSupported($extension)) { $this->extension = $extension; } } /** * @return string */ public function getBasename(): string { return $this->basename; } /** * @return bool */ public function isValid(): bool { return strlen($this->getBasename()) !== 0 && $this->hasExtension(); } /** * @return string */ public function assemble(): string { if ($this->hasExtension()) { return sprintf('%s.%s', $this->getBasename(), $this->getExtension()); } return $this->getBasename(); } } $file = 'Versicherungsschein/Nachträge'; var_dump(new Filename($file));

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.0040.01116.88
8.3.50.0110.00716.41
8.3.40.0110.00718.92
8.3.30.0060.00919.04
8.3.20.0060.00320.29
8.3.10.0040.00423.66
8.3.00.0040.00421.92
8.2.180.0100.01017.00
8.2.170.0140.00022.96
8.2.160.0120.00319.22
8.2.150.0050.00324.18
8.2.140.0000.00824.66
8.2.130.0050.00319.38
8.2.120.0080.00026.35
8.2.110.0060.00322.15
8.2.100.0060.00618.03
8.2.90.0040.00419.21
8.2.80.0000.00817.97
8.2.70.0030.00617.84
8.2.60.0050.00317.93
8.2.50.0080.00018.10
8.2.40.0040.00420.64
8.2.30.0040.00421.11
8.2.20.0050.00218.19
8.2.10.0040.00418.17
8.2.00.0000.00718.23
8.1.280.0120.00625.92
8.1.270.0070.00022.32
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0030.00723.92
8.1.230.0060.00622.21
8.1.220.0000.00817.74
8.1.210.0030.00518.77
8.1.200.0000.01017.60
8.1.190.0000.00817.38
8.1.180.0090.00018.10
8.1.170.0040.00418.96
8.1.160.0020.00519.05
8.1.150.0090.00020.69
8.1.140.0000.00719.63
8.1.130.0000.00718.92
8.1.120.0040.00417.68
8.1.110.0060.00617.63
8.1.100.0040.00417.52
8.1.90.0030.00517.53
8.1.80.0050.00217.67
8.1.70.0000.00717.64
8.1.60.0040.00417.69
8.1.50.0040.00417.67
8.1.40.0000.00817.57
8.1.30.0000.00817.80
8.1.20.0040.00417.82
8.1.10.0000.01017.68
8.1.00.0000.00817.63
8.0.300.0000.00918.77
8.0.290.0030.00616.88
8.0.280.0000.00718.54
8.0.270.0000.00717.27
8.0.260.0040.00416.95
8.0.250.0070.00017.12
8.0.240.0050.00317.17
8.0.230.0000.00717.08
8.0.220.0000.00717.12
8.0.210.0040.00417.11
8.0.200.0030.00317.21
8.0.190.0030.00617.00
8.0.180.0050.00216.95
8.0.170.0070.00017.10
8.0.160.0030.00516.96
8.0.150.0070.00017.02
8.0.140.0040.00417.08
8.0.130.0000.00613.43
8.0.120.0030.00616.95
8.0.110.0050.00216.97
8.0.100.0040.00417.07
8.0.90.0050.00316.91
8.0.80.0030.02017.01
8.0.70.0020.00517.12
8.0.60.0030.00617.14
8.0.50.0000.00716.95
8.0.30.0100.00717.25
8.0.20.0100.01017.43
8.0.10.0030.00517.23
8.0.00.0250.01916.91
7.4.330.0000.00615.55
7.4.320.0000.00616.89
7.4.300.0040.00416.68
7.4.290.0040.00416.76
7.4.280.0040.00416.86
7.4.270.0040.00416.77
7.4.260.0000.00513.47
7.4.250.0000.00716.63
7.4.240.0030.00316.68
7.4.230.0000.00716.73
7.4.220.0060.01316.86
7.4.210.0070.00716.70
7.4.200.0030.00516.94
7.4.160.0130.00716.77
7.4.150.0130.00717.40
7.4.140.0130.01017.86
7.4.130.0150.00416.77
7.4.120.0090.01216.77
7.4.110.0100.00716.74
7.4.100.0100.00716.71
7.4.90.0180.00016.54
7.4.80.0120.00619.39
7.4.70.0050.01316.68
7.4.60.0170.00316.67
7.4.50.0100.00316.75
7.4.40.0100.01016.61
7.4.30.0230.03116.73
7.4.00.0110.00715.06
7.3.330.0000.00513.52
7.3.320.0030.00313.54
7.3.310.0070.00016.35
7.3.300.0030.00316.45
7.3.290.0080.00816.56
7.3.280.0080.00816.56
7.3.270.0130.00717.40
7.3.260.0130.00816.67
7.3.250.0120.00616.69
7.3.240.0110.01216.71
7.3.230.0140.00916.73
7.3.210.0100.01416.41
7.3.200.0100.01016.49
7.3.190.0100.00916.74
7.3.180.0060.00916.77
7.3.170.0080.00816.45
7.3.160.0060.00916.85
7.3.120.0060.01115.12
7.3.110.0060.00814.90
7.3.100.0020.01315.08
7.3.90.0070.00815.16
7.3.80.0100.00715.02
7.3.70.0070.00715.03
7.3.60.0040.01315.07
7.3.50.0000.01015.03
7.3.40.0050.00814.82
7.3.30.0050.00714.84
7.3.20.0080.00516.85
7.3.10.0030.01016.85
7.3.00.0020.00916.73
7.2.330.0000.01817.04
7.2.320.0060.01617.00
7.2.310.0100.00716.79
7.2.300.0170.00716.58
7.2.290.0110.00616.85
7.2.250.0090.00915.21
7.2.240.0050.01215.35
7.2.230.0040.01115.08
7.2.220.0000.01315.25
7.2.210.0030.01215.18
7.2.200.0020.01015.34
7.2.190.0080.00715.07
7.2.180.0080.00815.27
7.2.170.0010.01115.16
7.2.160.0030.00915.23
7.2.150.0080.00817.27
7.2.140.0070.00716.96
7.2.130.0070.00317.07
7.2.120.0030.00817.25
7.2.110.0100.00616.95
7.2.100.0030.01217.24
7.2.90.0080.00915.96
7.2.80.0470.00515.90
7.2.70.0960.00816.11
7.2.60.0320.01016.14
7.2.50.0310.00616.30
7.2.40.1030.00816.12
7.2.30.0470.01516.18
7.2.20.0350.00516.11
7.2.10.0560.01216.22
7.2.00.0530.01016.16
7.1.330.0080.00616.06
7.1.320.0040.00716.02
7.1.310.0070.00715.89
7.1.300.0080.00416.06
7.1.290.0040.01015.94
7.1.280.0030.01216.09
7.1.270.0080.00615.79
7.1.260.0060.00815.79
7.1.250.0030.01015.91
7.1.210.0130.00613.95
7.1.200.0390.01113.98
7.1.190.1280.01314.14
7.1.180.0460.01414.09
7.1.170.0580.01614.28
7.1.160.1050.01414.21
7.1.150.1680.00914.09
7.1.140.0700.01214.18
7.1.130.1130.00314.20
7.1.120.0460.00714.05
7.1.110.1460.01013.90
7.1.100.1120.01014.21
7.1.90.0330.00714.12
7.1.80.0040.01214.05
7.1.70.0580.01014.24
7.1.60.0320.00332.03
7.1.50.0570.01332.40
7.1.40.1040.02932.21
7.1.30.0300.00532.07
7.1.20.1490.00632.16
7.1.10.0620.01514.24
7.1.00.1100.01314.20
7.0.310.3000.00313.39
7.0.300.0510.01013.70
7.0.290.1670.01013.53
7.0.280.1100.01013.64
7.0.270.1080.00313.59
7.0.260.1230.01713.84
7.0.250.1490.00713.62
7.0.240.1380.01013.88
7.0.230.0100.00313.52
7.0.220.0040.01113.56
7.0.210.0230.00713.59
7.0.200.0630.00713.54
7.0.190.0870.00713.61
7.0.180.0140.00613.55
7.0.170.0070.01113.59
7.0.160.0130.00313.20
7.0.150.0100.00713.61
7.0.140.0070.00813.60
7.0.130.0090.01413.70
7.0.120.0180.00013.46
7.0.110.1160.00613.30
7.0.100.1370.00313.71
7.0.90.1250.00513.41
7.0.80.1040.00613.25
7.0.70.1000.00313.39
7.0.60.1010.00313.09
7.0.50.1440.00613.62
7.0.40.0890.01013.80
7.0.30.1110.00613.80
7.0.20.1090.00913.48
7.0.10.0460.01213.57
7.0.00.0100.01013.48

preferences:
64.98 ms | 400 KiB | 5 Q