I have an array with multiple strings, like this:
$str[0] = \"kasdnkjsandjabsdkjsbad\";
$str[1] = \"kasdnkjsandjasdjksabdjkasbkjdsak\";
$str[2] = \"kasdnkjsa
Well, theoretically, this is pretty simple: just create a function that will "limit" the length of the string, and if it's too long, strip it off:
EDIT: if you want to "limit" the number of characters while adding them to the array, you can simply create a check in a function:
$length ) {
return false;
}
return $array[] = $value;
}
$strings = array( );
append( $strings, 'kasdnkjsandjabsdkjsbad' ); // is accepted.
append( $strings, 'kasdnkjsandjabsdkjsbadkasdnkjs' ); // is not accepted
append( $strings, 'kasdnkjsandsadbaskjdbsakjdbasdsadjsadjksabdk' ); // is not accepted.
// if you *really* want to exit when a value is too long:
function append_exit( $array, $value, $length = 25 ) {
if( mb_strlen( $value ) > $length ) {
trigger_error( 'Value is too long.', E_USER_ERROR );
exit;
}
return $array[] = $value;
}