denoteone Posted July 14, 2008 Share Posted July 14, 2008 I want to random show a banner on my site. I know there are a lot of scripts out there but i wanted to tweak one for my own use. the thing is I have both flash banners and animated gifs. I need help writing an if statement that checks the file that is randomly picked and echo's the correct tag (image or object) here is what I have so far. <?php $banners = array( "http://www.website.com,images/banner1.gif", "http://www.example.com,flash/banner2.swf", ); $randnum = rand(0, count($banners) - 1); $exploded = explode(",", $banners[$randnum]); $url = $exploded[0]; // Grab the URL for the banner $img = $exploded[1]; // Grab the image for the banner if ($img has ".gif") //this is were I am not sure of the syntax { echo "<a href=\"$url\">"; echo "<img src=\"$img\" border=\"0\" />"; echo "</a>"; } else { echo "flash movie tag " } ?> Link to comment https://forums.phpfreaks.com/topic/114667-random-banner/ Share on other sites More sharing options...
Dethman Posted July 14, 2008 Share Posted July 14, 2008 you mean this? elseif($img has ".swf"){ echo("<img src=\"$img\" border=\"0\" />"); } Link to comment https://forums.phpfreaks.com/topic/114667-random-banner/#findComment-589687 Share on other sites More sharing options...
denoteone Posted July 14, 2008 Author Share Posted July 14, 2008 in the first if statement i want to check if the file name has .gif in it. if so echo the <img> tag with the random chosen banner ad. if it does not have a .gif in the file name that means it is a .swf so I thought I could just use an else statement and then echo the flash object and embed tag with the random file name. Link to comment https://forums.phpfreaks.com/topic/114667-random-banner/#findComment-589693 Share on other sites More sharing options...
jkewlo Posted July 14, 2008 Share Posted July 14, 2008 i think not sure thou it would be == instead of has Link to comment https://forums.phpfreaks.com/topic/114667-random-banner/#findComment-589697 Share on other sites More sharing options...
.josh Posted July 14, 2008 Share Posted July 14, 2008 stristr() Link to comment https://forums.phpfreaks.com/topic/114667-random-banner/#findComment-589709 Share on other sites More sharing options...
denoteone Posted July 14, 2008 Author Share Posted July 14, 2008 this is what i have so far. <?php $banners = array( "http://www.website.com,images/Banner4.gif", "http://www.example.com,images/BANNER6.swf", ); $randnum = rand(0, count($banners) - 1); // Choose a random banner $exploded = explode(",", $banners[$randnum]); // Separate chosen banner by , $url = $exploded[0]; // Grab the URL for the banner $img = $exploded[1]; // Grab the image for the banner if(stristr($img, '.gif') === FALSE) { echo "<object id=\"OGBanner\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"468\" height=\"60\">"; echo "<param name=\"movie\" value=\"$img\" />"; echo "<!--[if !IE]>-->"; echo "<object type=\"application/x-shockwave-flash\" data=\"images/BANNER6.swf\" width=\"468\" height=\"60\">"; echo "<!--<![endif]-->"; echo "<p><a href=\"http://www.stratacahce.com/!0_OGWP.php\">Click for Organic Growth White Paper</a></p>"; echo "<!--[if !IE]>-->"; echo "</object>"; echo "<!--<![endif]-->"; echo "</object>"; }else { echo "<a href=\"$url\">"; echo "<img src=\"$img\" border=\"0\" />"; echo "</a>"; ?> I am saving this file as banners.php and including it in my html with <?php include("banners.php"); ?> the only thing showing in the banner spot is "; echo " ??? Link to comment https://forums.phpfreaks.com/topic/114667-random-banner/#findComment-589794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.