PHP subroutine - get additional info from text file?

PHP subroutine - get additional info from text file?

am 01.11.2007 10:45:16 von unknown

Post removed (X-No-Archive: yes)

Re: PHP subroutine - get additional info from text file?

am 01.11.2007 11:15:14 von Captain Paralytic

On 1 Nov, 09:45, Jenny Purcell wrote:
> Below is a subroutine built from code I found at PHPFreaks, and it
> works just as I'd expect it to. It lists all the files in a directory
> and creates links to them.
>
> I use it in a directory where each page is named for an animal, and
> the page profiles that pet. What I'd like to be able to do is create a
> separate text file in the same directory, with bits of information
> about each pet, then, have that information added on the same line as
> their link page.
>
> So, right now the list looks something like this:
>
> o fido.txt
> o mittens.txt
> o slither.txt
>
> What I'd like to be able to do is have a text file with lines this:
>
> slither.txt - my brand new Boa
> fido.txt - a 12 year-old English Bulldog.
> mittens.txt - my son's cute and fluffy kitten
> sylvester.txt - a black and white cat given to my cousin
>
> Then, when it displays on the page, I'd like it to display like this:
>
> o fido.txt - a 12 year-old English Bulldog.
> o mittens.txt - my son's cute and fluffy kitten
> o slither.txt - my brand new Boa
>
> The two elements that are important (other than getting the info line
> at all) is that the list in the text file can be in any order, and
> that entries could be in there that don't have link pages and they
> shouldn't be displayed.
>
> > // Links creating script taken from:http://www.phpfreaks.com/tutorials/146/0.php
> // Originally added October 21st, 2007
> // Modified by Jenny Purcell to be a subroutine to call it multiple
> times.
>
> function make_links($dir) { // create a user-defined function named
> make_links
> $files = scandir($dir);
> foreach($files as $ind_file){ // start foreach loop
> $letter = strtoupper(substr($ind_file,0,1));
> if($ind_file != '.' && $ind_file != '..') { // start
> if loop
> ?>
>

  • > href="">
    >

  • > > } // end if loop
    > } // end foreach loop
    >
    > } // end user-defined make_links function
    >
    > ?>

    This is not an SQL question and would be better asked in comp.lang.php

    Also, apologies, but your original post will now be archived!