What are the potential pitfalls of using str_replace to modify HTML content?

Using `str_replace` to modify HTML content can be risky because it operates on a string basis and may inadvertently modify parts of the HTML that you didn't intend to. This can lead to malformed HTML and unexpected behavior. To avoid this, it's recommended to use a DOM parser like `DOMDocument` to manipulate HTML content in a more structured and reliable way.

// Example of using DOMDocument to modify HTML content
$html = '<div><p>Hello, world!</p></div>';

$dom = new DOMDocument();
$dom->loadHTML($html);

// Modify the HTML content using DOM methods
$paragraph = $dom->getElementsByTagName('p')[0];
$paragraph->nodeValue = 'Goodbye, world!';

// Get the modified HTML content
$modifiedHtml = $dom->saveHTML($dom->documentElement);

echo $modifiedHtml;