function checkLength($input, $min, $max) { $length = strlen($input); if ($length < $min || $length > $max) { return "Input length must be between $min and $max characters."; } else { return true; } } $name = "John Doe"; if (!checkLength($name, 3, 20)) { echo "Invalid name length!"; }In the above code, the checkLength function takes three parameters: the input, the minimum length, and the maximum length. It then calculates the length of the input string using the strlen function and checks whether it falls within the specified range. If the length is outside the range, the function returns an error message. Otherwise, it returns true. The checkLength function is commonly used in form validation to ensure that user input is within a specific length. It is a built-in function in PHP, so there is no need for an external package or library to use it.