might be possible to make a slight improvement with:
//how long do you want the string?
$required_len = 5;
//the string
$str = "php";
//what do you want to fill the space with?
$fill = "-";
//get the length of $str
$actual_len = strlen($str);
//if string is too long
if ($actual_len > $required_len) {
$str = substr($str, 0, $required_len);
}
//if string is too short
elseif ($actual_len < $required_len) {
//($required_len - $actual_len) is amount of padding
$str = str_pad($str, $required_len - $actual_len, $fill);
}