What is the recommended approach in PHP to replace all characters in a string that are not letters or numbers with a specific pattern?
To replace all characters in a string that are not letters or numbers with a specific pattern in PHP, you can use a regular expression with the `preg_replace` function. The regular expression pattern `[^a-zA-Z0-9]` matches any character that is not a letter or a number. You can then replace these characters with your desired pattern, such as an underscore or an empty string.
$string = "Hello, World!123";
$pattern = '/[^a-zA-Z0-9]/';
$replacement = '_';
$new_string = preg_replace($pattern, $replacement, $string);
echo $new_string; // Output: Hello_World123