Daily Links

Posted on 2006-03-28
Last Modified: 2006-11-18

I'd like to create a script that displays a set of 2 unique links (with a description), for each day of the month.

Where the script pulls these links & descriptions from a .txt file (so I can easily update these links on a regular basis without editing the index.php file each time).

So, if one month has only 30 days, it would only display the first 60 links. If the next month has 31 days, it would display the first 62 links, and so on.

I'd like to keep security and performance in mind too.

Question by:xerospace
    LVL 17

    Expert Comment

    Hi xerospace,

    1. Check Current Date (Day of Month)
    2. Multiple by 2
    3. Use that # line and the next line in the the text file

    Try something like:

    // Get Current Day
    $day = date('j');
    $day *= 2;

    // Open textfile
    $fh = fopen('filename.txt', 'rb');

    // Get to the correct line in file:
    for ($i = 0; $i < $day ** !feof($fh); $i++)

    // Read the next two lines and print them
    if (!feof($fh))
      print fgets($fh);
      print '<br>';
      print fgets($fh);
      print 'Error, two few lines in file or error in code';

    // Close the file


    Try that out.  I did not test the code but I expect it should work alright.  You can test it out more specifically if you give a number for each line in the textfile so if it works you see which lines are printing:
    1. Line One blah blha
    2. Line Two blahlahdlak

    Joe P

    Author Comment

    Hi Joe,

    Sorry about the delayed response. I apologize.

    I've been trying to get this script to work, but it keeps giving me a parse error on line 11.

    Any ideas?

    Thanks again!
    LVL 17

    Accepted Solution

    I must have pressed the wrong key, they are right next to eachother * and &

    This line:
    for ($i = 0; $i < $day ** !feof($fh); $i++)
    Should be:
    for ($i = 0; $i < $day && !feof($fh); $i++)

    I'm sorry about that =)

    Author Comment

    Thanks! I added some extra points.
    LVL 17

    Expert Comment

    Glad it worked =)
    Thanks for the extra points!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now