My Ad Rotator

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

My Ad Rotator

Post by Vegan »

I have this ad program, and wanted to be sure I can use multi line ads so I can use JavaScript based ads in addition to <iframe> and <img> type ads.

<?php
$fcontents = join ('', file ('banner_ads.txt'));
$s_con = split("~",$fcontents);
$banner_no = rand(0,(count($s_con)-1));
echo $s_con[$banner_no];
?>

The code looks for a ~ on a line as the object separator. I was only concerned with an ad over several lines.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: My Ad Rotator

Post by requinix »

If your server runs on a system where line breaks are represented as ~s then you may have some problems.
But if not, and newlines are \r\n, \r, or \n, then everything should be fine.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: My Ad Rotator

Post by Chalks »

tasairis wrote:system where line breaks are represented as ~s
What system(s) represent line breaks as ~s?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: My Ad Rotator

Post by requinix »

Chalks wrote:
tasairis wrote:system where line breaks are represented as ~s
What system(s) represent line breaks as ~s?
It was sarcasm.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: My Ad Rotator

Post by Vegan »

So the punch line is this code will suffice as is?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: My Ad Rotator

Post by Syntac »

You might want to use explode() instead. Basically the same thing as split(), but *probably* faster.
baoky
Forum Newbie
Posts: 12
Joined: Sat May 24, 2008 6:21 am

Re: My Ad Rotator

Post by baoky »

explode will help the script more.Image
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: My Ad Rotator

Post by Vegan »

Right now I have PHP5 on the machine, but I noticed PHP6 is up & coming. Any concerns with the widget?

I going to review explode and see if it is really worth the change, as is it serves the ads I have now, I wanted to see how big of an ad I can feed it.

Hard to find good books, I live in a smaller city
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply