I would like the function to return a boolean, where TRUE would mean that the string is within and FALSE means that the string length is invalid and will change the part of the code where the function is used.
In addition, I would revise the function as follows:
function is_string_length_correct( $string, $min, $max ) { $l = mb_strlen($string); return ($l >= $min && $l <= $max); }
The part of the code that uses this function may look like this:
if (!is_string_length_correct($string, $min, $max)) { echo "Your string must be at least $min characters long at at most $max characters long"; return; }
source share