How can the str_replace function be utilized to replace commas with periods in PHP?

To replace commas with periods in a string using the str_replace function in PHP, you can simply pass the comma as the search parameter and period as the replace parameter. This function will search for all occurrences of commas in the string and replace them with periods.

$string = "This, is, a, sample, string";
$updated_string = str_replace(",", ".", $string);
echo $updated_string;