By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,433 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

PHP - Random Links

P: n/a
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">what will be funny</a>
<a href="http://www.url.com/this-is-good.shtml">this 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">what was funny</a>
<a href="http://www.url.com/that-will-be-bad.shtml">this will be bad</a>
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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:
http://nl2.php.net/manual/nl/function.fread.php
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($handle))
{
$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:
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">what will be funny</a>
<a href="http://www.url.com/this-is-good.shtml">this 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">what was funny</a>
<a href="http://www.url.com/that-will-be-bad.shtml">this will be bad</a>


Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.