3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ 'this is a test! this is a test! this is a test! this is a test! this is a test! cmyk derp.png', ' this is a test! this is a test! this is a test! this is a test! this is a test! cmyk x.png ', ' this is a test! this is a test! this is a test! this is a test! this is a test! cmykx .png ', ' this is a test! this is a test! this is a test! this is a test! this is a test! derpderp .png ', ' this is a test! this is a test! this is a test! this is a test! this is a test! derpd .png ', ' this is a test! this is a test! this is a test! this is a test! this is a test! derp .png ', ' this is a test! this is a test! this is a test! this is a test! this is a test.png ', 'this is a test! this is a test! this is a test! this is a test! this is a - - - - - - test.png', 'this is a test! this is a test! this is a test! this is a test! this is a test! this is a test! this is a test! .png', 'this is a test! this is a test! this is a test! this is a test! this is a test! thisx is a test! this is a test! .png', 'this is a test! this is a test! this is a test! this is a test! this is a test! thisxy is a test! this is a test! .png', ]; foreach ( $tests as $originalFilename) { $filteredFilename = str_replace(' ', '-', strtolower(trim($originalFilename))); $filteredFilename = substr( $filteredFilename, 0, strrpos($filteredFilename,'.') ); $filteredFilename = preg_replace('/(\bcmyk\b)|([^a-z0-9\-]+)|(\-+$)/','',$filteredFilename); $filteredFilename = preg_replace('/-{2,}/','-',$filteredFilename); $filteredFilenameLength = strlen($filteredFilename); if ( $filteredFilenameLength > 80 ) { if ($filteredFilename[80] === '-') { echo 'case 1', PHP_EOL; $filteredFilename = substr($filteredFilename, 0, 80); } else { echo 'case 2', PHP_EOL; $filteredFilename = substr($filteredFilename, 0, strrpos($filteredFilename, '-', 80 - $filteredFilenameLength)); } } else { echo 'case 3', PHP_EOL; } echo $filteredFilenameLength, ' ', strlen($filteredFilename), ' ', $filteredFilename, PHP_EOL; }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
case 3 79 79 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-derp case 3 76 76 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-x case 3 80 80 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-cmykx case 2 83 74 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test case 3 80 80 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-derpd case 3 79 79 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-derp case 3 74 74 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test case 3 74 74 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test case 2 104 79 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this case 1 105 80 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-thisx case 2 106 74 this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test

preferences:
207.13 ms | 405 KiB | 214 Q