What are the best practices for handling character restrictions in PHP forms to accommodate server limitations?

When handling character restrictions in PHP forms to accommodate server limitations, it is important to validate user input on the client-side using JavaScript to prevent users from entering more characters than allowed. Additionally, server-side validation should also be implemented to ensure that the input does not exceed the server limitations. This can be done by using PHP's `strlen()` function to check the length of the input and display an error message if it exceeds the limit.

$input = $_POST['input_field'];

// Check if input exceeds character limit
if(strlen($input) > 50) {
    echo "Input exceeds character limit of 50 characters";
    // Handle error accordingly
} else {
    // Process the input if it meets the character limit
}