{"id":12,"date":"2008-08-15T20:07:33","date_gmt":"2008-08-16T04:07:33","guid":{"rendered":"http:\/\/kevware.wordpress.com\/?p=26"},"modified":"2008-08-15T20:07:33","modified_gmt":"2008-08-16T04:07:33","slug":"php-code-share-random-this-random-that","status":"publish","type":"post","link":"https:\/\/www.kevware.com\/geek\/php-code-share-random-this-random-that\/","title":{"rendered":"PHP Code Share &#8211; Random this, random that"},"content":{"rendered":"<p>Sorry on the long delay between posts.\u00a0 Been very busy at work, and sometimes haven&#8217;t had the brain energy to do even MORE web stuff in the off-hours.\u00a0 But I&#8217;m definitely due so the next item is an easy one to work my way back into postings:\u00a0 an easy to use random script.<\/p>\n<p>Now I&#8217;ve seen many out there that claim to be simple, and then you start adding in files and iframes and that somehow doesn&#8217;t seem very simple in application.\u00a0 So after trying a few things (a random link list for my home page, and a random image selector as well for the home page), here is what I settled on.<\/p>\n<p>The Random Link script I use is one that I had actually found for use on another site.\u00a0 It&#8217;s original purpose was to display random banners (with links) on a web page.\u00a0 It worked very well and was very easy to adapt.\u00a0 That was a few years ago.\u00a0 I revisited the script while looking for others and realized it could be adapted easily to just display random links&#8230; or probably anything else.<\/p>\n<p>Here is the original code:<br \/>\n&lt;?php<\/p>\n<p>\/\/You will have to change the ban1, ban2, and ban3\u00a0 variables.\u00a0 You can change these links to point at the images you want displayed.<br \/>\n\/\/You will have to change the url1, url2, and url3\u00a0 variables.\u00a0 You want these to be urls of the pages you want to link to.<br \/>\n$ban1 = &#8220;http:\/\/xxx.org\/images\/ads\/banner.gif&#8221;;<br \/>\n$url1 = &#8220;http:\/\/www.xxx.org&#8221;;<br \/>\n$ban2 = &#8220;http:\/\/yyy.org\/images\/ads\/banner.jpg&#8221;;<br \/>\n$url2 = &#8220;http:\/\/www.yyy.org&#8221;;<br \/>\n$ban3 = &#8220;http:\/\/zzz.org\/images\/ads\/banner.gif&#8221;;<br \/>\n$url3 = &#8220;http:\/\/www.zzz.org&#8221;;<br \/>\n$target = &#8220;_blank&#8221;;<\/p>\n<p>\/\/Random number between 1 and number of banners.<br \/>\n$randomNum = rand (1,3);<\/p>\n<p>\/\/Select the banner of the random number<br \/>\n$image = ${&#8216;ban&#8217;.$randomNum};<\/p>\n<p>\/\/Url of the random number<br \/>\n$url= ${&#8216;url&#8217;.$randomNum};<\/p>\n<p>\/\/Prints out the link of the banner and the image of the banner<br \/>\nPrint &#8220;&lt;a href=&#8221;.$url.&#8221; mce_href=&#8221;.$url.&#8221; target=&#8221;.$target.&#8221;&gt;&lt;img src=&#8221;.$image.&#8221; border=0&gt;&lt;\/a&gt;&#8221;;<br \/>\n?&gt;<\/p>\n<p>Pretty straightforward, huh?\u00a0 So I took it and decided to use it just for random links:<br \/>\n&lt;?php<\/p>\n<p>$url1 = &#8220;http:\/\/www.google.com&#8221;;<br \/>\n$url2 = &#8220;http:\/\/www.yahoo.com&#8221;;<br \/>\n$url3 = &#8220;http:\/\/www.yocisco.com&#8221;;<br \/>\n$url4 = &#8220;http:\/\/www.rafaelnadal.com&#8221;;<br \/>\n$url5 = &#8220;http:\/\/www.wimbledon.org&#8221;;<br \/>\n$url6 = &#8220;http:\/\/www.odcdance.org&#8221;;<br \/>\n$url7 = &#8220;http:\/\/www.cuil.com&#8221;;<br \/>\n$url8 = &#8220;http:\/\/www.youtube.com&#8221;;<br \/>\n$url9 = &#8220;http:\/\/www.vrestaurant.com&#8221;;<br \/>\n$url10 = &#8220;http:\/\/www.atptennis.com&#8221;;<br \/>\n$url11 = &#8220;http:\/\/www.wheresgeorge.com&#8221;;<br \/>\n$url12 = &#8220;http:\/\/www.laughingsquid.net&#8221;;<br \/>\n$url13 = &#8220;http:\/\/www.blogger.com&#8221;;<br \/>\n$url14 = &#8220;http:\/\/www.meebo.com&#8221;;<br \/>\n$url15 = &#8220;http:\/\/www.usopen.org&#8221;;<br \/>\n$url16 = &#8220;http:\/\/www.campstella.org&#8221;;<br \/>\n$url17 = &#8220;http:\/\/www.youtube.com\/watch?v=2keyIEof038&#8221;;<br \/>\n$target = &#8220;_blank&#8221;;<\/p>\n<p>\/\/Random number between 1 and number of banners.<br \/>\n$randomNum = rand (1,17);<\/p>\n<p>\/\/Select the banner of the random number<br \/>\n\/\/$text = ${&#8216;ban&#8217;.$randomNum};<\/p>\n<p>\/\/Url of the random number<br \/>\n$url= ${&#8216;url&#8217;.$randomNum};<\/p>\n<p>\/\/TEST TEXT<br \/>\n$static1= &#8220;Random Link &#8220;;<\/p>\n<p>\/\/TEST TEXT<br \/>\n$static2= &#8220;&#8230; Give it a shot!&#8221;;<\/p>\n<p>\/\/Prints out the link of the banner and the image of the banner<br \/>\nPrint &#8220;&lt;a href=&#8221;.$url.&#8221; mce_href=&#8221;.$url.&#8221; target=&#8221;.$target.&#8221;&gt;&lt;span&gt;&#8221;.$static1.&#8221;&lt;\/span&gt;&lt;span&gt;&lt;em&gt;&#8221;.$static2.&#8221;&lt;\/em&gt;&lt;\/span&gt;&lt;\/a&gt;&#8221;;<br \/>\n?&gt;<\/p>\n<p>Isn&#8217;t simplicity a wonderful thing????? \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sorry on the long delay between posts.\u00a0 Been very busy at work, and sometimes haven&#8217;t had the brain energy to do even MORE web stuff in the off-hours.\u00a0 But I&#8217;m definitely due so the next item is an easy one to work my way back into postings:\u00a0 an easy to use random script. Now I&#8217;ve &#8230; <span class=\"more\"><a class=\"more-link\" href=\"https:\/\/www.kevware.com\/geek\/php-code-share-random-this-random-that\/\">[Read more&#8230;]<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-admin","4":"post-12","6":"format-standard","7":"category-php-code"},"_links":{"self":[{"href":"https:\/\/www.kevware.com\/geek\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kevware.com\/geek\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kevware.com\/geek\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kevware.com\/geek\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kevware.com\/geek\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":0,"href":"https:\/\/www.kevware.com\/geek\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kevware.com\/geek\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kevware.com\/geek\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kevware.com\/geek\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}