Results 1 to 14 of 14

Thread: PHP Programming, or Perl or whatever

  1. #1
    VBSpike
    Guest

    PHP Programming, or Perl or whatever

    Hi. I have no idea how to program in PHP or Perl, but I hope you can help. Is there a way to save a file on a server (like a text file) using PHP or Perl and then retrive that data from the server (for example like creating a poll - you save the number of answers for each question and then retrive the data to show the results). Any help would be greatly appreciated.

    Also, if you know the answer to above question, the second part would be: how do you read the file from the server line by line (if it's even possible) and store that data in an array?

    Thanks
    Spike

  2. #2
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    Why don't you learn a little about PHP or Perl first. We could help you better that way.

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  3. #3
    VBSpike
    Guest
    First of all I know that much

    Second I don't have really have time to do much research on PHP or Perl at this moment. School is killing me, my boss just wants the job done (using PHP or Perl - bastard) and I already sleep 3 hours a night

    Thanks anyway

    Spike

  4. #4
    scoutt
    Guest
    your best bet would to be to save the data in a database, being a flat file or Mysql

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    mySQL is easy but probably too powerful for a poll...

  6. #6
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    Perl example:

    Code:
    $file = "poll.txt";
    $input = "this is my result";
    
    #create a file and add to it,  INPUTPOLL is the file handler this can be any name you like 
    open (INPUTPOLL, "> $file) or die "can't  open file for input";
      print INPUTPOLL $input;
    close INPUTPOLL;
    
    #open the file and read the contents
    open (OUTPUTPOLL, "< $file") or die "can't open file for output";
      $poll_results = <OUTPUTPOLL>;
    close OUTPUTPOLL;
    
    #display in browser
    print"Content-Type: text/html\n\n";
    print $poll_results;
    some things you should know about opening files:

    if you notice in the open line there is a > or a <
    > means create or overwrite
    >> (not used above) means create, and append
    < means open file for readiing

    You can not open a file for writing and reading at the same time!!

    This should get u started!

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    PHP Code:
         $fp = @fopen("poll.txt""r");
             
    fpassthru ($fp);
         @
    fclose ($fp); 
    Opening and displaying file poll.txt in PHP

    You can open for write and read access at the same time!

  8. #8
    scoutt
    Guest
    Originally posted by da_silvy
    mySQL is easy but probably too powerful for a poll...
    oh I don't know about that, it's what I use

  9. #9
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    for a noob

    i think he should learn text files, then databases.

  10. #10
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    for a noob

    I think he should learn text files, then databases.
    I second that, although something as simple as a poll would be a good stepping stone to a DB from a flat file system ( for a learning project in the future ).

    Both have there advantages working with flat files you tend to pick up a lot of pattern matching skills, and working with databases, well, you pick up SQL skills!

    IMHO: for such a simple project as a poll it's more time efficient to write a script for a flat file than a DB!

  11. #11
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    In Perl, you could use a DBM file (or emulation) to bind a hash to a file.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Perl doesn't really take that long. I would suggest finding some tutorials. Reading and writing files are one of the first things that are probably covered.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    scoutt
    Guest
    Originally posted by progressive


    I second that, although something as simple as a poll would be a good stepping stone to a DB from a flat file system ( for a learning project in the future ).

    Both have there advantages working with flat files you tend to pick up a lot of pattern matching skills, and working with databases, well, you pick up SQL skills!

    IMHO: for such a simple project as a poll it's more time efficient to write a script for a flat file than a DB!
    I would have to agree too, but I passed the flat file up and went to mysql when I learned. I think the flat file is hard to learn for me that is. but everybody has their choice.

  14. #14
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Yeah...

    I think database is more convenient.

    IMHO: PHP is better than perl too


    I just like it more...

    I haven't put much effort into learning perl, but PHP is pretty easy to pick up

Posting Permissions

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



Click Here to Expand Forum to Full Width