This is more of underlying PHP execution question.
What are the positives or negatives to the two following methods for limiting string size?
function max_length($string, $length) {
return (strlen($string) > $length)?substr($string, 0, $length):$string;
}
substr($string, 0, $length);
The case I am worried about is when the string is smaller than the length requested. Can it cause buffer overflow errors? Extra whitespace? Repeated characters?
The only thing I do know is that speed-wise, substr
is at least 2x faster than the custom function provided.