How can PHP developers prevent the automatic conversion of \n to new lines in database outputs?

When retrieving data from a database in PHP, the \n character may be automatically converted to new lines, which can affect the formatting of the output. To prevent this conversion, developers can use the PHP function `str_replace` to replace \n with a different character that won't be converted to a new line.

// Retrieve data from the database
$data = "This is a\nsample\nstring";

// Replace \n with a different character
$fixed_data = str_replace("\n", "\\n", $data);

// Output the fixed data
echo $fixed_data;