What are the potential issues with using preg_replace in PHP for text manipulation, as seen in the forum thread?

The potential issue with using preg_replace in PHP for text manipulation is that it can be vulnerable to code injection if not used properly. To solve this issue, it is recommended to use the preg_replace_callback function instead, which allows you to specify a callback function to process the matched strings.

// Example of using preg_replace_callback to safely manipulate text
$text = "Hello, <script>alert('You have been hacked!')</script>";
$clean_text = preg_replace_callback('/<[^>]*>/', function($matches) {
    return ''; // Replace any HTML tags with an empty string
}, $text);

echo $clean_text; // Output: Hello,