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

Ad rotation on a website

P: n/a
Hi Everyone,

I am having trouble looking for a script that will rotate images from
a standard text file.

I have a folder set up with two images that rotate every time the page
is refreshed. They also have a hyperlink so that when an image/ad is
clicked on it goes to the advertiserments web address.
The only problem is that the path to the images and corresponding
hyperlink are in a javascript file.

Is it possible to reference them from a standard text file so that a
non-techie can login to webedit pro and edit the image name and url
everytime the ad is being changed ?

The script can be java scrip or preferably PHP, once it can reference
a .txt file...Im happy

Any help would be very much appreciated...

Stephen

Feb 22 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
photo.txt

one.jpg,http://www.enemy.be,two.jpg,http://www.tuinwijk32.be
index.php (in same dir as pictures and textfile)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>read file</title>
</head>

<body>
<?php
$i = 0; // counter
$myFile = "photo.txt"; // file to read
$fh = fopen($myFile, 'r'); // open file to read
$theData = fread($fh, filesize($myFile)); // read the complete file
fclose($fh); // close connection to file
$part1 = split(",", $theData); // split at comma

foreach($part1 as $waarde) {
$kolom[$i] = $waarde; // put data in array ($kolom)
$i++; // counter = counter++
}
// $kolom[0] = foto1.jpg - $kolom[2] = foto2.jpg
$getal = ((rand(1, 2))%2 == 0) ? 0 : 2; // randomize
echo("<a href=\"" . $kolom[$getal + 1] . "\"><img src=\"" .
$kolom[$getal] . "\" alt=\"" . $kolom[$getal] . "\"></a>");
?>
</body>
</html>

Hope this helps

st***********@gmail.com schreef:
Hi Everyone,

I am having trouble looking for a script that will rotate images from
a standard text file.

I have a folder set up with two images that rotate every time the page
is refreshed. They also have a hyperlink so that when an image/ad is
clicked on it goes to the advertiserments web address.
The only problem is that the path to the images and corresponding
hyperlink are in a javascript file.

Is it possible to reference them from a standard text file so that a
non-techie can login to webedit pro and edit the image name and url
everytime the ad is being changed ?

The script can be java scrip or preferably PHP, once it can reference
a .txt file...Im happy

Any help would be very much appreciated...

Stephen
Feb 22 '07 #2

P: n/a
<comp.lang.php>
<>
<22 Feb 2007 05:55:27 -0800>
<11*********************@s48g2000cws.googlegroups. com>
Is it possible to reference them from a standard text file so that a
non-techie can login to webedit pro and edit the image name and url
everytime the ad is being changed ?

The script can be java scrip or preferably PHP, once it can reference
a .txt file...Im happy
It would be quite easy to write a small script that would let you
add/edit the 2 line text file for each rotating banner .

text file 1
images/banner_one.jpg
http://www.yourdomain.com/cgi?=make

text file 2
images/banner_two.jpg
http://www.whatever.com/blah.html

On your actual webpage that uses them - its just a matter of generating
a random number in order to display the banner and use the url that
accompanys it .

Assuming you have 10 banners you want to rotate .....

rnd=(10)

Assuming the above picks 4 as the random number .....

file="banners/4.txt";
read line 1
read line 2

<divhref=url image </div>

I suppose you dont really need to write a suitable script in you create
the text files offline and upload & for the most part you would only
really need to generate a random number and read the 2 lines of text to
be used .
--
www.phptakeaway.co.uk
(work in progress)
Feb 22 '07 #3

P: n/a
Rik
On Thu, 22 Feb 2007 14:55:27 +0100, <st***********@gmail.comwrote:
Hi Everyone,

I am having trouble looking for a script that will rotate images from
a standard text file.

I have a folder set up with two images that rotate every time the page
is refreshed. They also have a hyperlink so that when an image/ad is
clicked on it goes to the advertiserments web address.
The only problem is that the path to the images and corresponding
hyperlink are in a javascript file.

Is it possible to reference them from a standard text file so that a
non-techie can login to webedit pro and edit the image name and url
everytime the ad is being changed ?

The script can be java scrip or preferably PHP, once it can reference
a .txt file...Im happy

Any help would be very much appreciated...

Check out fgetcsv(), and possibly fputcsv() if you want to make an
interface to it later.
--
Rik Wasmus
Feb 23 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.