August 1st, 2009 by admin0
The following code determines the number of Fridays in a month :
$year = 2008;
$month = 1; //Aug
$day = 1;
$startDate = mktime(0, 0, 0, $month, $day, $year);
$NoD = date( “t”, $startDate);
While(date( “D”, $startDate) != “Fri”) //find first Friday
{
$day++;
$startDate = mktime(0, 0, 0, $month, $day, $year);
}
$day–;
$days = ceil(($NoD-$day)/7);
echo “$days Fridays”;
Replace the $month=1; to the number of the [...]
«« Read More
August 1st, 2009 by admin0
This is a PHP Function to get the name of the variable (not the value) :
function getvarname(&$var)
{
$ret = ”;
$tmp = $var;
$var = md5(uniqid(rand(), TRUE));
$key = array_keys($GLOBALS);
foreach ( $key as $k )
if ( $GLOBALS[$k] === $var )
{
$ret = $k;
break;
}
$var = $tmp;
return $ret;
}
$another = ‘test’;
$testvar = ‘test’;
echo getvarname($testvar); //echoes ‘testvar’
?>
«« Read More
August 1st, 2009 by admin0
Following code in php displays how many weeks and days left when a start date and an end date is given:
function daysWeeks($start,$end)
{
$days_left=$end-$start;
$weeks = (int) ($days_left / 7) ;
$days = $days_left % 7;
echo “$weeks weeks and $days days left!”;
}
$start=”05/08/2008″;
$end=”25/08/2008″;
daysWeeks($start,$end);
«« Read More
July 31st, 2009 by admin0
1.Create a .txt file, say hit.txt.
2. Enter the value 0 in hit.txt and save.
3. Create a php file, say counter.php with the following code…
«« Read More