Interactive PHP console
php -a
On Ubuntu there is necessary to install this package:
apt-get install php5-readline
Working with dates
Compute date shifted against the present:
date('Y-m-d', strtotime(date("Y-m-d")." +1 day"));
Difference of two dates
$datetime1 = new DateTime('2005-05-26 10:06:15');
$datetime2 = new DateTime('2014-11-30');
$interval = $datetime1->diff($datetime2);
echo $interval->format('"It happened %y years plus %m' months ago...");
Calling classes functions with variable names:
class myclass {
static function say_hello()
{
echo "Hello!\n";
}
}
$classname = "myclass";
call_user_func(array($classname, 'say_hello'));
call_user_func($classname .'::say_hello'); // As of 5.2.3
$myobject = new myclass();
call_user_func(array($myobject, 'say_hello'));
?>