echo "new filename is ".$text; if ( strlen ($text) >= 5) { $text = substr ($text, 0, 4); echo "new filename is ".$text; }