note 73823 added to function.mt-rand
| From: | php-general at lists dot php dot net | Date: | Mon, 12 Mar 2007 08:36:01 +0000 |
| Subject: | note 73823 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124365@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 ....
I Forgot something, sorry for that, but here is the correction.
<?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: 212.124.37.9
Probable Submitter: 80.139.229.214
----
Manual Page -- http://www.php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/73823
Del: integrated -- https://master.php.net/note/delete/73823/integrated
Del: useless -- https://master.php.net/note/delete/73823/useless
Del: bad code -- https://master.php.net/note/delete/73823/bad+code
Del: spam -- https://master.php.net/note/delete/73823/spam
Del: non-english -- https://master.php.net/note/delete/73823/non-english
Del: in docs -- https://master.php.net/note/delete/73823/in+docs
Del: other reasons-- https://master.php.net/note/delete/73823
Reject -- https://master.php.net/note/reject/73823
Search -- https://master.php.net/manage/user-notes.php