Skip to main content

Posts

Showing posts from May, 2010

Days difference

Ever wanted to know the number of days that have been passed since the beginning of this 2010 and the number of days passed since your birthday ? Then try this code: <?php function noofdays($day_1,$day_2) { $diff = strtotime($day_2) - strtotime($day_1) + 1; //Find the number of seconds $day_difference = ceil($diff / (60*60*24)) ; //Find how many days that is return $day_difference; } $bday='1985-06-18'; // My birthday, replace it with yours' $day1=date("Y-01-01"); // Start date of current year $day2=date("Y-m-d"); // Today's date //$diff = strtotime($day2) - strtotime($day1) + 1; //Find the number of seconds //echo ceil($diff / (60*60*24)) ; //Find how many days that is $x= noofdays($day1,$day2); $y= noofdays($bday,$day2); echo 'No of days passed this year = '.$x; echo '<br>'; echo 'No of days passed from my birthday till date = '.$y; ?>

File and Dir names

If you ever wanted to know the file and directory names that you are working upon, this piece of code might help you. <?php // __FILE__ represents C:\xampp\htdocs\dirname.php echo 'The current file: '.'<b>'.__FILE__.'</b><br><br>'; echo 'DIR name using dirname(__FILE__): '.'<b>'.dirname(__FILE__).'</b><br><br>'; // returns C:\xampp\htdocs echo 'Current working directory using getcwd(): '.'<b>'.getcwd().'</b><br><br>'; // returns C:\xampp\htdocs echo 'Basename of current file: '.'<b>'.basename(__FILE__).'</b><br><br>'; //returns dirname.php echo 'Basename of current directory: '.'<b>'.basename(dirname(__FILE__)).'</b><br><br>'; //returns htdocs $arrStr = explode("/", $_SERVER['SCRIPT_NAME'] ); $arrStr = array_reverse($arrStr ); ec