What alternative PHP function can be used to replace tabs with spaces while preserving line breaks?

To replace tabs with spaces while preserving line breaks in PHP, you can use the `str_replace()` function along with the `PHP_EOL` constant to replace tabs with spaces and keep the line breaks intact. This allows you to maintain the structure of the text while converting tabs to spaces.

$string_with_tabs = "This\tis\ta\tstring\nwith\ttabs\n";
$spaces_per_tab = 4;

$replaced_string = str_replace("\t", str_repeat(" ", $spaces_per_tab), $string_with_tabs);
echo $replaced_string;