How can you replace a specific character in a string with HTML formatting in PHP?

To replace a specific character in a string with HTML formatting in PHP, you can use the str_replace() function. Simply specify the character you want to replace, the HTML formatting you want to insert, and the original string as parameters. This function will replace all occurrences of the specified character with the specified HTML formatting.

<?php
$string = "Hello, world!";
$charToReplace = ",";
$htmlFormatting = "<br>";

$newString = str_replace($charToReplace, $htmlFormatting, $string);

echo $newString;
?>