Page 1 of 1

My Ad Rotator

Posted: Thu Oct 30, 2008 5:22 pm
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.

Re: My Ad Rotator

Posted: Thu Oct 30, 2008 8:08 pm
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.

Re: My Ad Rotator

Posted: Fri Oct 31, 2008 9:02 am
by Chalks
tasairis wrote:system where line breaks are represented as ~s
What system(s) represent line breaks as ~s?

Re: My Ad Rotator

Posted: Fri Oct 31, 2008 10:33 am
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.

Re: My Ad Rotator

Posted: Sat Nov 01, 2008 10:52 am
by Vegan
So the punch line is this code will suffice as is?

Re: My Ad Rotator

Posted: Sat Nov 01, 2008 11:27 am
by Syntac
You might want to use explode() instead. Basically the same thing as split(), but *probably* faster.

Re: My Ad Rotator

Posted: Sat Nov 01, 2008 3:45 pm
by baoky
explode will help the script more.Image

Re: My Ad Rotator

Posted: Sun Nov 02, 2008 9:45 am
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