If I make a simple text file such as the following:
first line.
second line.
And apply fread in the following way:
$fh = fopen("test_file_three.txt",'r') or die("Error attempting to
open file.");
$first_word = fread($fh,5);
$second_word = fread($fh,6);
$third_word = fread($fh,1);
$fourth_word = fread($fh,3);
echo $first_word;
echo "<br />";
echo $second_word;
echo "<br />";
echo $third_word;
echo "<br />";
echo $fourth_word;
echo "<br />";
The echo of the $third_word variable is just, as expected, "blank". I assume it takes in and stores the new line character. However, if I append the following code:
if ($third_word === '\n'){
echo "Third word is newline character.";
}
else {
echo "Third word is not newline character.";
}
(or, alternatively, == instead of ===) Then it comes out as false; testing $newline_char = '\n'; in such an if statement, however, works fine. What is happening here?, is a newline character being stored?