What are best practices for formatting text output in PHP to avoid spacing issues when writing to a file?

When writing text output to a file in PHP, it's important to ensure that the formatting is consistent to avoid spacing issues. One way to do this is by using the PHP `trim()` function to remove any leading or trailing whitespace from the text before writing it to the file. This will help eliminate any unintended spacing that may occur.

// Example code snippet to write formatted text output to a file
$output = "This is some text output with spacing     ";
$output = trim($output); // Remove leading and trailing whitespace

$file = fopen("output.txt", "w");
fwrite($file, $output);
fclose($file);