-
Pet Projects
Tag Archives: PHP
Here is a very interesting post regarding LAMP (Linux, Apache, MySQL and PHP). I agree with the post all the way. So whats the problem here? Well I think one of the key issues is that LAMP focus on solving … Continue reading
Given 2008-01-31 as the current date and the value of “$days_before” is 2, the code will echo 2008-01-29. The date 2 days before the current date. $days_before = 2; $current_date = date(’Y-m-d’); $str = strtotime($current_date)-(86400*$days_before); //1 day has 86400 echo … Continue reading
Here is how you get the number of days between two dates. function getdays($day1,$day2) { return round((strtotime($day2)-strtotime($day1))/(24*60*60),0); } $begin = date("Y-m-d"); // we set today as an example $end = "2007-01-29"; echo getdays($begin,$end).’ days’; This was taken from … Continue reading
A short but complete tutorial on how to write a Chat Application using PHP, AJAX and XML. Developers talk a lot about community when the term Web 2.0 comes up. And whether you think it’s hype or not, the idea … Continue reading
From jansch.nl: This is not the best way to escape data. The most important reason is security. addslashes can lure you into a false sense of security. As Chris Shiflett points out, there are situations that addslashes doesn’t escape. Use … Continue reading
What is a Singleton? In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the … Continue reading
I have been handling file uploads in most of my web applications. Sometimes, I store them in databases and sometimes I feel like storing them in directories. This post will not deal with uploading files, but rather downloading them. Basically, … Continue reading
This news has circulating around the PHP Community for a few days already – posting it here for record purposes. As a php web developer, you should know that php is probably the language that has the biggest code repository. … Continue reading
UPDATE 2008-10-24 This guy has an updated post for Zend_Captcha. Mine is old an out-dated. Here is how to create a simple Captcha image with the Zend Framework. I have created this controller named: ImagegeneratorController. The job of this controller … Continue reading
Here is how to get the difference between two dates in PHP. … public static function toTimestamp($date){ $arrayDate=self::toArray($date); return mktime($arrayDate[’hour’],$arrayDate[’minute’],$arrayDate[’second’],$arrayDate[’month’],$arrayDate[’day’],$arrayDate[’year’]); } public static function dateDiff($date1,$date2,$unit=’HOUR’){ $date1=self::toTimestamp($date1); $date2=self::toTimestamp($date2); $secs=$date1-$date2; switch(strtoupper($unit)){ case ‘WEEK’:return $secs/60/60/24/7; break; case ‘DAY’:return $secs/60/60/24; break; … Continue reading