3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0alpha1
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