How can PHP be optimized to efficiently filter out unwanted characters from a large dataset?

To efficiently filter out unwanted characters from a large dataset in PHP, you can use the `preg_replace` function with a regular expression pattern that matches the unwanted characters. This can help optimize the filtering process and improve performance.

// Define the unwanted characters pattern
$pattern = '/[^a-zA-Z0-9]/';

// Filter out unwanted characters from the dataset
$filtered_data = preg_replace($pattern, '', $large_dataset);

// Output the filtered data
echo $filtered_data;