Created
November 27, 2017 14:37
-
-
Save janrenn/7455d16644f07a05cef14b9a8bd560a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//truncation | |
//------------- | |
$ext = end( explode( '.', $filename ) ); | |
$filename = substr( $filename, 0, -(strlen($ext) + 1) ); | |
$filename = str_replace( '.', '-', $filename ); | |
$filename_shortened = substr( $filename, 0, 70 ); | |
if ( $filename_shortened != $filename ) { | |
$filename = preg_replace( '~(-|_)[^\-_]{0,' . floor( strlen($filename) / 2 ) . '}$~', '', $filename_shortened ); | |
} | |
$filename = trim( $filename, '-_' ); | |
$filename = $filename . '.' . $ext; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment