What are the advantages and disadvantages of using regular expressions (like preg_replace) for formatting text in PHP?
Regular expressions like preg_replace can be powerful tools for formatting text in PHP. They allow for complex search and replace patterns, making it easy to manipulate text in specific ways. However, regular expressions can also be difficult to write and debug, especially for beginners. Additionally, they may not always be the most efficient solution for simple text formatting tasks.
// Example of using preg_replace to format text in PHP
$text = "Hello, this is a sample text with some numbers like 12345.";
$formatted_text = preg_replace('/\d+/', '<strong>$0</strong>', $text);
echo $formatted_text;