the following is part of myfunction which opens a file and places the pointer at the end. It then tests each character $char in reverse order until it finds a newline or a carriage return character.
The problem is it is not recognising these characters.
The function is as follows:
while(count($results) < $limit && fseek($this->_pointer, $offset, SEEK_END) >= 0) {
$char = fgetc($this->_pointer);
if($char == '\n' || $char == '\r'){
print("YAY");
$offset --;
$data = $this->explodeData(fgets($this->_pointer, 1024));
array_push($results, $this->formatRow($data));
}
$offset--;
}
It never manages to print("YAY") however it is successfully testing each character. The file it is reading definitely has newlines in it.
(The file was created by another function and has had "\n" inserted in it, this is showing inside it and is showing in my IDE successfully as being on alternate lines).
Does anyone know why it is unable to recognise these newline characters?
You are using
'\n'instead of"\n".