PHP - Random Links

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • \(a\)

    PHP - Random Links

    Hi

    I'm wondering if someone might be able to provide me with a few lines of
    code to complete the following task in PHP.

    I have three text files (a.txt, b.txt, c.txt), each containing text.

    The script would randomly take a line of text from each file, merge them to
    make a phrase and hyperlink it to a url with dashes between the words. The
    output from the script would be vertical. Each time the script runs, the
    output would be different.

    The script would have a variable x that could be set to say how many lines
    of output there would be.

    Thanks for the help and I have an example below to clarify.

    *************** ***

    Contents of a.txt

    this
    that
    what

    Contents of b.txt

    will be
    was
    is

    Contents of c.txt

    good
    bad
    funny

    *************** ****

    In the php script, x=5

    An example of the output of the script which is vertical consists of 5
    hyperlinks.

    <a href="http://www.url.com/what-will-be-funny.shtml">wh at will be funny</a>
    <a href="http://www.url.com/this-is-good.shtml">thi s is good</a>
    <a href="http://www.url.com/that-is-bad.shtml">that is bad</a>
    <a href="http://www.url.com/what-was-funny.shtml">wh at was funny</a>
    <a href="http://www.url.com/that-will-be-bad.shtml">this will be bad</a>


  • warstar

    #2
    Re: PHP - Random Links

    yeah maybe try to write it your self here are some tips:
    to open a file read: http://nl2.php.net/manual/nl/function.fopen.php
    to read data from the file c:

    to check if the file has anded c(u can make a file statement using
    this)): http://nl2.php.net/manual/nl/function.feof.php

    a well i dunno never read from files but u can make some kinda array
    like this:
    $filename = "/usr/local/something.txt";
    $handle = fopen ($filename, "r");
    while(!feof($ha ndle))
    {
    $start[] = fread ($handle, filesize ($filename));
    }
    fclose ($handle);

    and do this 3 time's so u get like 3 array 1 called start 1 called
    middel and 1 called end then u just take a random like
    this(http://nl2.php.net/manual/nl/function.array-rand.php):
    $rand_keys = array_rand ($start);
    echo $start[$rand_keys];

    and do this 3 times u could make some nice function out of this but he
    your the 1 that gone make it :D

    Good luck



    On Sat, 11 Oct 2003 20:56:28 GMT, "\(a\)" <no@spam.com> wrote:
    [color=blue]
    >Hi
    >
    >I'm wondering if someone might be able to provide me with a few lines of
    >code to complete the following task in PHP.
    >
    >I have three text files (a.txt, b.txt, c.txt), each containing text.
    >
    >The script would randomly take a line of text from each file, merge them to
    >make a phrase and hyperlink it to a url with dashes between the words. The
    >output from the script would be vertical. Each time the script runs, the
    >output would be different.
    >
    >The script would have a variable x that could be set to say how many lines
    >of output there would be.
    >
    >Thanks for the help and I have an example below to clarify.
    >
    >************** ****
    >
    >Contents of a.txt
    >
    >this
    >that
    >what
    >
    >Contents of b.txt
    >
    >will be
    >was
    >is
    >
    >Contents of c.txt
    >
    >good
    >bad
    >funny
    >
    >************** *****
    >
    >In the php script, x=5
    >
    >An example of the output of the script which is vertical consists of 5
    >hyperlinks.
    >
    ><a href="http://www.url.com/what-will-be-funny.shtml">wh at will be funny</a>
    ><a href="http://www.url.com/this-is-good.shtml">thi s is good</a>
    ><a href="http://www.url.com/that-is-bad.shtml">that is bad</a>
    ><a href="http://www.url.com/what-was-funny.shtml">wh at was funny</a>
    ><a href="http://www.url.com/that-will-be-bad.shtml">this will be bad</a>
    >[/color]

    Comment

    Working...