473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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">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
1 3143
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Papa Legba | last post by:
I have huge page of links, to whcih I am currently adding. I would like to add a "random link" button which would parse the current page, extract all URLs then load a random link. Before I start...
1
by: Global_Killa | last post by:
Hey all, I'm new to java script, and really don't know anything about it. I'm looking to have a random link shown on my site. I want the link to be chosen from a list of about 10 links. How would...
1
by: Kim Scarborough | last post by:
I found this bookmarklet that will go to a random link on the currently open page: javascript:void(location.href=document.links) Could this be changed to go to a random link from the bookmarks...
3
by: TaTonka | last post by:
hi! how can i manage it (html or jscript with css) that everytime a user loads or refreshes a page, the page has a new bgcolor. i want to put it in a single file, so that all my pages have the...
10
by: Marshall Belew | last post by:
I'm trying to synchronize a network app that uses random numbers generated by System.Random. Rather than pass every randomly generated number, I just pass the seed. I'm seeing a result that leads...
2
by: mikeoley | last post by:
Ok I have a Javascript slideshow working. Every image is linked to a another page in the site. Problem is...The link wont refresh to the next link once the second images rollovers in the slideshow....
3
by: duffint | last post by:
Hi there, I have this script that I need some direction in; it's mangled my head a bit. I want to be able to stick links around six random words; these links are then popup ads. I saw kind...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I generate a random integer from 1 to N?...
7
by: Brian | last post by:
Hi there I have been looking for a script that can randomly rotate 8 different images on 1 page. I used to have a script that did this but can't find it now. I have found loads of script that...
10
by: moonhkt | last post by:
Hi All Below coding for generate a file. Do you know how to write a code for random a a file for multi-user access ? We want testing FileSystem IO performance. #include <fcntl.h> #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.