SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Guru coiL's Avatar
    Join Date
    Sep 2001
    Location
    QLD, Australia
    Posts
    666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy $fp ? yet another newbie question

    could someone please tell me what fp stands for/means

    used in:
    PHP Code:
    $fp fopen("order.txt""a");
    if (!
    $fp)
    {
    echo 
    "<p>Your order could not be processed at this time</p>.";
    exit; 
    coiL
    "cradled in the learning curve"

  2. #2
    SitePoint Enthusiast Fluffy bunny slippers's Avatar
    Join Date
    Oct 2001
    Location
    outside your house
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $fp is just a variable it could have the value of anything.

    $fp = anything you like.
    If you like the look of my slippers you should see my undies!

  3. #3
    SitePoint Addict
    Join Date
    Feb 2002
    Location
    Atlanta, GA
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As a newbie you should really get to know the manual:

    http://www.php.net/manual/en/

    Definately keep aking questions here, but the maual is invaluable as a referance resource, and it has a decent "newbie" tutorial.


  4. #4
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    guys, you could have been more useful by adding that, in this particular case (looking at the code) $fp is a file pointer (hence the name...it's actually a bit of a standard to call it $fp, if i'm not mistaken), as it holds information which enables other functions etc to access that particular file that you opened with the fopen function...

    but yeah...
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  5. #5
    SitePoint Addict s|k's Avatar
    Join Date
    Apr 2002
    Location
    Hilo, Hawai'i
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually that is not a complete answer. You can call it what you want, but its not just any variable. Its the handle that this particular php script will assign the file you opened. Certain functions dealing with files will use that "handle" to recognize the open file and refer to it. fread() uses it, fclose() uses it. When dealing with files, directories, or MySQL queryies you will run across this type of variable, often times they are optional.

  6. #6
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    slk
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  7. #7
    SitePoint Addict s|k's Avatar
    Join Date
    Apr 2002
    Location
    Hilo, Hawai'i
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew someone would beat me to it..dang it!
    Last edited by s|k; May 3, 2002 at 07:38.

  8. #8
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your post was more accurate though...i didn't use the word "handle" anywhere in my sentence
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  9. #9
    SitePoint Addict
    Join Date
    Feb 2002
    Location
    Atlanta, GA
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, what is a "handle/pointer" you say?

    if you echo( $fp ) you'll get something like Resource ID #1

    So when you write:

    $fp = fopen("Yadda", w+);

    the PHP engine assigns the returned value i.e. the Resource id, of your fopen() call to $fp.

    Later when you use $fp in the engine knows exactly where to go to perfome the requested action.

    Or that's how I understand it.

    Please correct me if I'm wrong.

    Pete


  10. #10
    SitePoint Addict s|k's Avatar
    Join Date
    Apr 2002
    Location
    Hilo, Hawai'i
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by redux
    your post was more accurate though...i didn't use the word "handle" anywhere in my sentence
    okay, feel a little bit better, but I didnt mention the pointer part like you did which he's gonna need to know about if he wants to read his files more than once in a script
    Last edited by s|k; May 3, 2002 at 07:57.

  11. #11
    SitePoint Guru coiL's Avatar
    Join Date
    Sep 2001
    Location
    QLD, Australia
    Posts
    666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am actually slogging my way through a book which I had been told was for beginners. They just tend to leave the explainations of things out a bit. (keep saying how if i know c++ then it should be familiar)

    pity I don't know anything but a bit of html


    In this case I was trying to work out why they named the variable $fp and not something else.

    thanks for the answers though
    they helped .. sort of
    coiL
    "cradled in the learning curve"

  12. #12
    SitePoint Addict s|k's Avatar
    Join Date
    Apr 2002
    Location
    Hilo, Hawai'i
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    hehehe, I 'm never answering another one of these threads again

    kidding

  13. #13
    SitePoint Guru coiL's Avatar
    Join Date
    Sep 2001
    Location
    QLD, Australia
    Posts
    666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok so fp pretty much stands for File pointer

    so what is a file pointer?
    coiL
    "cradled in the learning curve"

  14. #14
    SitePoint Addict
    Join Date
    Feb 2002
    Location
    Atlanta, GA
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Remember it can be anything, $fp just happens to be the example here.

    You could say something like:

    $AnnaKournikova = fopen("How to date a hockey player in violation of the Mann act.txt", r);

    The pointer/handle part is PHP's way of identifying the file in the fopen() call, or fread(), or fwrite().


  15. #15
    SitePoint Addict s|k's Avatar
    Join Date
    Apr 2002
    Location
    Hilo, Hawai'i
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by coiL
    ok so fp pretty much stands for File pointer

    so what is a file pointer?
    $fp should be renamed to $RTFM

  16. #16
    SitePoint Addict s|k's Avatar
    Join Date
    Apr 2002
    Location
    Hilo, Hawai'i
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay, a file pointer does two things. One it lets the script know which open file you are talking about. But it also has the second function of letting the script no what part of the file you are at in reading it.

    say for instance this imaginary contents of a textfile:

    This is a line of text in a text file.
    This is a second line of text in a text file.

    when you first open the file the file pointer is at the beginning of the text. When you read the file line by line, after reading the first line your filepointer is now at the beginning of the second line. If you want to re-read the first line you have to rewind using a function you'll have to lookup to return to the beginning of the text(hint: it "REWINDS"). If you read the secondline next, the file pointer will now be at the end of the file. You can also use fseek() which will look for text and move your filepointer there.

    Am I making sense? Am I wrong? Am I being too nice?

  17. #17
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by s|k
    Am I making sense? Am I wrong? Am I being too nice?
    yes you are... no you aren't i guess... and no you're not being too nice


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •