How can regular expressions be effectively used in PHP to manipulate and format text, as shown in the provided code snippet?

Regular expressions can be effectively used in PHP to manipulate and format text by using functions like preg_replace() to search for specific patterns and replace them with desired text. In the provided code snippet, we can use a regular expression to remove all non-alphanumeric characters from a string. This can be useful for cleaning up user input or formatting data for storage or display.

$text = "Hello, 123 world!";
$clean_text = preg_replace('/[^A-Za-z0-9]/', '', $text);
echo $clean_text; // Output: Hello123world