How can PHP best practices be applied to efficiently extract specific information from a textarea input in PHP?

When extracting specific information from a textarea input in PHP, it is best practice to sanitize the input to prevent any malicious code injection. One way to efficiently extract specific information is by using regular expressions to match the desired content within the textarea input.

// Sanitize the textarea input
$textarea_input = $_POST['textarea_input'];
$clean_input = htmlspecialchars($textarea_input);

// Extract specific information using regular expressions
if (preg_match('/specific_pattern/', $clean_input, $matches)) {
    $specific_info = $matches[0];
    echo "Specific information extracted: " . $specific_info;
} else {
    echo "Specific information not found.";
}