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! this is a test! cymk derp.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! cymk x.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.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.png', ]; foreach ( $tests as $originalFilename) { $filteredFilename = str_replace(' ', '-', strtolower(trim($originalFilename))); $filteredFilename = substr( $filteredFilename, 0, strrpos($filteredFilename,'.') ); $filteredFilename = str_replace('cmyk','',$filteredFilename); $filteredFilename = preg_replace('/(cmyk)|([^a-z0-9]+)|(\-+$)/','',$filteredFilename); $filteredFilename = preg_replace('/-{2,}/','-',$filteredFilename); if ( strlen($filteredFilename) > 80 ) { if ($filteredFilename[81] === '-') { $filteredFilename = substr($filteredFilename, 0, 80); } else { echo strrpos($filteredFilename, '-', 80); $filteredFilename = substr($filteredFilename, 0, 80); } } echo $filteredFilename; }
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0beta1
thisisatestthisisatestthisisatestthisisatestthisisatestthisisatestcymkderpthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestcymkxthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatest