CommonClass.php 847 Bytes
<?php

/**
 * @class CommonClass
 * @brief Collection of some common function
 * @details
 */
class CommonClass
{
	/*
	 * @brief generate a random string
	*/
	public static function generateRandomString($length = 10) {
		$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
		$randomString = '';
		for ($i = 0; $i < $length; $i++)
			$randomString .= $characters[rand(0, strlen($characters) - 1)];
		return $randomString;
	}

	/*
	 * @brief timestamp to DDTime conversion
	*/
	public static function timeStampToDDTime($timeStamp)
	{
		$y = date("Y",$timeStamp);
		$d = date("z",$timeStamp);
		if (strlen($d) == 0)
			$d = "000";
		else if (strlen($d) == 1)
			$d = "00".$d;
		else if (strlen($d) == 2)
			$d = "0".$d;
		$t = date("His",$timeStamp)."000";
		return $y.$d.$t;
	}
}

?>