PHPBuilder - Random Image Class



RSS Twitter
Snippets Html

Random Image Class

by: einav
|
September 10, 2001

Version: 1.0

Type: Class

Category: HTML

License: GNU General Public License

Description: this simple class is used to show a random image from an array of image paths. see class for usage..



class RndImage{
/********************************************************************
* Random Image Class
* Version: 1.0
* Date: 9/9/2001
* License: GPL
* Author: einav brill 
* Contact: einavb@email.com
* Description: 
*  	this simple class is used to show a random image from an array
* 	of image paths.
* Functions:
*	setPath(image_path) is used to set the images path.
*	insertRndImage(imgs) used to get a list of images path
*	getRndImage() return a random image path
* Usage:
* $rndImg = new RndImage();
* $rndImg->setPath('images/rotating_images/');
* $rndImg->insertRndImage('image_1.jpg','image_2.jpg','image_3.jpg',etc..);
* HTML....<? echo $rndImg->getRndImage(); ?>.....HTML 
**********************************************************************/
var $_path ;
var $_imgArray ;

function setPath($pathName){
$this->_path = $pathName;
}    

function insertRndImage($imgs)
{
$imgArraySize = func_num_args();
 for($imgNum=0;$imgNum<$imgArraySize;$imgNum++)
  {
  $this->_imgArray[$imgNum] = $this->_path.func_get_arg($imgNum);
  }
}

function getRndImage(){
srand ((double) microtime() * 1000000);
$rndValue = rand(0,sizeof($this->_imgArray)-1);
return $this->_imgArray[$rndValue];
 }
}

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
einav

Comment:



Comment:

(Maximum characters: 1200). You have characters left.