note 73810 added to function.mt-rand
| From: | bjoern dot lange at cd-dash dot com | Date: | Sun, 11 Mar 2007 14:52:54 +0000 |
| Subject: | note 73810 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124345@lists.php.net to get a copy of this message | ||
In one of my forums was a discussion about, how to change an image randomly, so i wrote this code
using mt_rand ....
I hope you can use it ....
<?php
//ImageChange.php
error_reporting(0);//hide the notice for the missing $iRand
$sPath2ImageDir = Path;//preventing redundancy
$aImages = scandir($sBildOrdnerPfad);//Dir 2 Array
$iImageCount = count($aImages);//preventing redundancy
while (getimagesize("{sPath2ImageDir}/{$aImages[$iRand]}")) {//recursion to get an image
$iRand = mt_rand(2, $iImageCount-1);//min = 2 because $aImages[0] = "." and
$aImages[1] = ".."
echo "<img alt=\"Image{$iRand}\"
src=\"{sPath2ImageDir}/{$aImages[$iRand]}\" title=\"Image{$iRand}\"
/>";//show the image
unset($aImages, $iImageCount, $iRand, $sBildOrdnerPfad);//if this script is used in another script
?>
----
Server IP: 217.13.201.10
Probable Submitter: 84.62.136.33
----
Manual Page -- http://www.php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/73810
Del: integrated -- https://master.php.net/note/delete/73810/integrated
Del: useless -- https://master.php.net/note/delete/73810/useless
Del: bad code -- https://master.php.net/note/delete/73810/bad+code
Del: spam -- https://master.php.net/note/delete/73810/spam
Del: non-english -- https://master.php.net/note/delete/73810/non-english
Del: in docs -- https://master.php.net/note/delete/73810/in+docs
Del: other reasons-- https://master.php.net/note/delete/73810
Reject -- https://master.php.net/note/reject/73810
Search -- https://master.php.net/manage/user-notes.php