How can I read text data from a file in PHP without including the newline character?
When reading text data from a file in PHP, the newline character (\n) is often included at the end of each line. To read text data without including the newline character, you can use the rtrim() function to remove any trailing whitespace, including newline characters. This function will strip any whitespace characters (including newline characters) from the end of a string.
$file = fopen("data.txt", "r");
if ($file) {
while (($line = fgets($file)) !== false) {
$line = rtrim($line); // Remove newline character
echo $line . "<br>";
}
fclose($file);
}