What is the best practice for saving values from text fields in PHP?

When saving values from text fields in PHP, it is important to sanitize the input to prevent SQL injection attacks and other security vulnerabilities. One common method is to use the `filter_input()` function along with the `FILTER_SANITIZE_STRING` filter to clean the input before saving it to a database or using it in any other way.

// Get the value from a text field and sanitize it
$value = filter_input(INPUT_POST, 'text_field', FILTER_SANITIZE_STRING);

// Check if the value is not empty before saving it
if (!empty($value)) {
    // Save the sanitized value to a variable or database
    $clean_value = $value;
} else {
    // Handle empty input error
    echo "Input cannot be empty.";
}