Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7014477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:31:34+00:00 2026-05-27T22:31:34+00:00

the following is part of myfunction which opens a file and places the pointer

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:31:35+00:00Added an answer on May 27, 2026 at 10:31 pm

    You are using '\n' instead of "\n".

    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--;
    }
    
    "\n" == LF character
    '\n' == '\n';
    
    // Variables are effected also
    $var = 'foo';
    
    print "$var"; // prints 'foo';
    print '$var'; // prints '$var';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following is part of service layer which is provided by WCF service : [Serializable]
I'm trying to get a regex which is able to find the following part
I wrote the following part which is a Java method with two STRING arguments
I have the following part of a program, which emulates a very basic menu.
I have the following part of a data frame which is much bigger than
I have following part of xml file. <UN N=@U1> <DT N=24/06/2011> <PN N=@P1> <TM
I'm following part of this Railscast and trying to load a static file using
I have the following part of a CSV File with 7 columns (see first
I have a complicated xml file and in different levels the following part may
I'm currently doing the following as part of my iPhone application NSArray *paths =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.