Random logo v2 (Snippet)
If you wish to post tutorials or need help with any web programming language that isnt listed above then please post them in here.
3 posts
Page 1 of 1
Hello,
Earlier today I found #lola90235's tutorial for displaying random logo on page so I decided to make it a bit more advanced and availible both in JavaScript and PHP (therefore it was posted in other languages lol)
JavaScript
If you need more explanation about the code, feel free to comment below.
Thanks for reading this snippet,
-Filip
Earlier today I found #lola90235's tutorial for displaying random logo on page so I decided to make it a bit more advanced and availible both in JavaScript and PHP (therefore it was posted in other languages lol)
JavaScript
Code: Select all
PHP<!doctype html>
<html>
<head>
<title>Random logo test</title>
</head>
<body>
<img src="" id="logo" />
<script type="text/javascript">
var logoCount = 10; //Number of logo files
var logoParent = "logo"; //ID of logo holder
var fileNamePattern = "images/logo[num].png"; //Pattern of filename
var num = logoCount + 1;
var r=Math.floor(Math.random()*num);
document.getElementById(logoParent).src = fileNamePattern.replace("[num]", r);
</script>
</body>
</html>
Code: Select all
Report bugs if you find any. <?php
function generateNewLogo() {
define("logoCount", 10); //Number of logo files
define("logoParent", "logo"); //ID of logo holder
define("fileNamePattern", "images/logo[num].png"); //Pattern of filename
$logo = rand(0, logoCount); //Get a random number
$path = str_replace("[num]", $logo, fileNamePattern); //Put number in pattern
return $path; //Return parsed pattern
}
?>
<!doctype html>
<html>
<head>
<title>Random logo test</title>
</head>
<body>
<img src="<? echo generateNewLogo(); ?>" id="logo" />
</body>
</html>
If you need more explanation about the code, feel free to comment below.
Thanks for reading this snippet,
-Filip
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo![]()
no screen :lol:
love to try this out
love to try this out

visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
Dummy1912 wrote:no screen :lol:It's just a snippet lol
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo![]()
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023