Looping files

Discussion in 'PHP' started by Michael_Tanner, Jun 6, 2009.

  1. #1
    I'm currently trying to script something that requires me to script in PHP, of which I'm brand new to. I'm trying to make it read a specific file (that contains a number of course), and it loops through that number. I have files that should be labeled accordingly through each loop. So, if the number in the first file is '127', it loops 127 times and opens all .txt files between 1 and 127, though I can't get it to work.

    Here's the code:
    
    <html>
    <head>
    <title>Taco Bell</title>
    </head>
    
    <body>
    <?php
    $handle = fopen("forumcount.txt", "r");
    $filename = fread($handle, filesize("forumcount.txt"));
    $i = 0;
    while ( $i <= $filename )
    {
       $fi = $i . '.txt';
       "<a link type="text" href="$fi" />Post $fi</a>";
       $i++;
    }
    ?>
    
    </body>
    </html>
    
    Code (markup):
    Though, every time I open the page, rather than applying links, it just shows the following: Post $fi"; $i++; } ?> , as plain text.

    Could anyone help?
     
    Michael_Tanner, Jun 6, 2009 IP
  2. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #2
    Please take a look at echo: http://www.w3schools.com/php/func_string_echo.asp

    Here is the updated line: echo "<a link type=\"text\" href=\"".$fi."\" />Post ".$fi."</a><br>";

    Note how the quotes are escaped and the $fi variable is concatenated with the string.
     
    Social.Network, Jun 7, 2009 IP