SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    Fluffy Kitten Programmer~ Elledan's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    1,356
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could probably find it one the 'net, but it's late, I'm tired and I've to work tomorrow

    This belongs in the Beginner's Corner, I think, but I'll post it here anyway.

    What's the most common way to use text files together with PHP? I want to use it for a links page and later maybe more.

    Thanks for your time!
    www.nyanko.ws - My web-, software- and game development company.
    www.mayaposch.com - My personal site and blog.

  2. #2
    SitePoint Member
    Join Date
    Jul 2000
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Elledan...

    There are two ways, one, is just parse the form data and save it together with the HTML you want to go with the links, for example...

    The form returns:

    $linkname = "Yahoo";
    $linkurl = "http://www.yahoo.com/";

    Then, you save the file with
    <?php
    $oldfile = file ("path/to/file.txt");
    $towrite = "<a href=\"$linkurl\">$linkname";
    for ($i = 0; $i <= count ($oldfile); $i++){
    $towrite .= "$oldfile[$i]";
    }
    $fp1 = fopen ("path/to/file.txt", "w");
    fputs ($fp, $towrite);
    fclose($fp1);
    ?>

    The second type is to build your own database format, and I've been using this method.

    The .txt file might look like...

    |Yahoo|http://www.yahoo.com/|
    |SitePoint|http://www.sitepoint.com/|
    |CCN|http://www.ichacha.net/|

    ... try figuring out the code yourself, it's much or less the same as the one on top.

    Hope that helps
    - Jeramii-chan (Jeremy)
    _____________________________
    a@hk : http://www.animehk.com/

  3. #3
    Fluffy Kitten Programmer~ Elledan's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    1,356
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help! I think I got a basic idea of how to do it now
    www.nyanko.ws - My web-, software- and game development company.
    www.mayaposch.com - My personal site and blog.

  4. #4
    SitePoint Member
    Join Date
    Jul 2000
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome
    Hope that helps
    - Jeramii-chan (Jeremy)
    _____________________________
    a@hk : http://www.animehk.com/


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
  •