PDA

View Full Version : Need help redoing PERL in PHP!


Jaiem
Thu 19th Sep '02, 5:07pm
I have a simple PERL script that is a random banner rotator and display. It is called via the SSI include command.

Nothing fance, just opens a file that lists banner URL's and the URL's to go to when clicked, then selects one at random and includes it along with the appropriate HTML code in the main (calling) HTML program.

How can I make a PHP version of this simple script? IOW, I need some PHP code that will open a file of banners and links (in the format BANNER URL|LINK URL), select a record at random and display the banner with link in the mainline program.

Thanks in advance!

Dimava
Thu 19th Sep '02, 10:24pm
www.planetsourcecode.com search for banner and you'll find a few code snipplets ;)

-Dimava

filburt1
Thu 19th Sep '02, 10:31pm
If the format is like this:

image url|href\n
image url|href\n
.
.
.

...then I'm trying to write something now, but beware that if you want to use it in your forums that means putting it in the phpinclude template, and I'm willing to bet that since nearly every page access that template that server load could shoot up.

filburt1
Thu 19th Sep '02, 10:39pm
$contents = file('test.txt');
$whichone = rand(0, sizeof($contents) - 1);
$s = explode('|', $contents[$whichone]);
$imghref = trim($s[0]);
$linkhref = trim($s[1]);
echo "Click here, fool!<br><a href=\"$linkhref\"><img src=\"$imghref\"></a><br><br>";

...but if you want it to be in a template on your forums:

$contents = file('test.txt');
$whichone = rand(0, sizeof($contents) - 1);
$s = explode('|', $contents[$whichone]);
$imghref = trim($s[0]);
$linkhref = trim($s[1]);
$banner = "Click here, fool!<br><a href=\"$linkhref\"><img src=\"$imghref\"></a><br><br>";

...then put $banner in whatever template you want the banner to appear.