Changing 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:

Changing my ad rotator

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: Changing my ad rotator

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Changing my ad rotator

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: Changing my ad rotator

Post by ell0bo »

That's how I figured they'd be but I just wanted to make sure. Yeah, you're fine just outputting them.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Changing my ad rotator

Post 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;

?>

Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: Changing my ad rotator

Post 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.
Post Reply