Page 1 of 1

Changing my ad rotator

Posted: Mon Apr 05, 2010 11:15 am
by Vegan
My PHP ad rotator at present works OK for the limited number of ads I have, no problem.

I have expanded my choice of ads significantly so i need to generalize.

Given an array of strings called ads

I have a specific one $ad that the advertiser supplied code.

so should I just echo "($ad)"; to show the ad string, which already is <href> or <iframe> etc.

Re: Changing my ad rotator

Posted: Mon Apr 05, 2010 11:27 am
by ell0bo
If it's an iframe, or another element, then you're safe to just output it at it's position. However, if it's an href, you're going to need to wrap it in an <a> achor.

If you give me a better sample of that data you're getting, I might be able to help you more.

Re: Changing my ad rotator

Posted: Mon Apr 05, 2010 11:36 am
by Vegan
The code has the <a ...> anchor already, here are some samples of my ads for you to see.

ads[9] = '<iframe src="http://rcm.amazon.com/e/cm?t=cpa07-20&o ... YXG2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>';

ads[10] = '<a href="http://www.anrdoezrs.net/click-2957329-10651177" target="_blank"><img src="http://www.1and1affiliate.com/uploads/p ... id=2957329" style="border: 0 none;"/></a>';

These are taken from a JavaScript block, I am planning to cut/paste them into PHP when the code is righteous.

Re: Changing my ad rotator

Posted: Mon Apr 05, 2010 12:11 pm
by ell0bo
That's how I figured they'd be but I just wanted to make sure. Yeah, you're fine just outputting them.

Re: Changing my ad rotator

Posted: Mon Apr 05, 2010 12:50 pm
by Vegan
Seems to be a problem, out is "Array" and no ad, where did I go wrong?

Code: Select all

<?

// Tower Ads intended for display below the navigation block
// The ad size needs to be 120x600 which is called a wide scyscraper

$ads = array(
	///////////////////////////
	// Link Share
	///////////////////////////

	// Microsoft Store
	array(
		'<a href="http://click.linksynergy.com/fs-bin/click?id=jaxflTaXP3Y&offerid=166833.10000258&subid=0&type=4"><IMG border="0"   alt="Microsoft Store" src="http://ad.linksynergy.com/fs-bin/show?id=jaxflTaXP3Y&bids=166833.10000258&subid=0&type=4&gridnum=16"></a>'
	),
	array(
		'<a href="http://click.linksynergy.com/fs-bin/click?id=jaxflTaXP3Y&offerid=166833.10000297&subid=0&type=4"><IMG border="0"   alt="Microsoft Store" src="http://ad.linksynergy.com/fs-bin/show?id=jaxflTaXP3Y&bids=166833.10000297&subid=0&type=4&gridnum=16"></a>'
		),
	array(
		'<a href="http://click.linksynergy.com/fs-bin/click?id=jaxflTaXP3Y&offerid=166833.10000285&subid=0&type=4"><IMG border="0"   alt="Microsoft Store" src="http://ad.linksynergy.com/fs-bin/show?id=jaxflTaXP3Y&bids=166833.10000285&subid=0&type=4&gridnum=16"></a>'
	),
);
 
$ad = $ads[array_rand($ads)];
echo $ad;

?>


Re: Changing my ad rotator

Posted: Mon Apr 05, 2010 1:40 pm
by ell0bo
I'm not sure why you're making it a double array? Perhaps you come from a C++ background where strings are arrays in hiding?

Either way, drop that second array reference, because when you do $ads[0] you get an Array not a string as you'd want.

that, or when you call $ads[array_rand($ads)] make it $ads[array_rand($ads)][0], but that's just ugly.