Monday, May 23, 2011

Calculating differences between two date in months and days

<?php
$date1 = $TPC_From;
$date2 = $TPC_To;
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d bulan, %d hari\n", $months, $days);  ?>

You can customize the code using your own purposes..

Thursday, May 5, 2011

HTML button tag

Do you know that the button tag in Internet Explorer will submit the text between the <button> and </button> tags but other browsers will submit the content of the value attribute as we want it to be. In IE we have to use the input element to create buttons in an HTML form, But it still can't bring the value as I want. The value attribute is the button label.


Is there a chance that IE can take value in button tag..I have try in IE 8, it can but I got a problem with compatibility view..



Friday, April 15, 2011

for each in php

1. For each bring one value at a time

<?php

 $fruit
= array( "Banana","Apple", "Plum");

foreach (
$fruit as $fruit_name)
{
    echo 
"$fruit_name<br/>\n";
}
?>
 


The above will display:
Banana
Apple
Plum 
2. For each bring two value in the array


<?php

$fruitColours 
= array("Banana" => "Yellow","Apple"  => "Green","Plum"   => "Purple");

foreach (
$fruitColours as $fruit_name => $fruit_colour)
{
    echo 
"$fruit_name is $fruit_colour<br/>\n";
}
?>




The above will display:
Banana is Yellow
Apple is Green
Plum is Purple

LinkWithin

Related Posts Plugin for WordPress, Blogger...