<?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;
}
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
thisisatestthisisatestthisisatestthisisatestthisisatestthisisatestcymkderpthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestcymkxthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatestthisisatest