Testing a few lines of PHP

Did you ever need to test just a few lines of PHP without wanting to bootstrap your entire script or application? Try using PHP's interactive shell on the command line using the -a option. I typically use the interactive shell for testing date formats and regular expressions.

nathan@rg-ubuntu:~$ php -a
Interactive shell
php > $date = '4/1/2009';
php > echo date('M Y', strtotime($date));
Apr 2009
php > $regex = '|\[nid:(\d*)\]|';
php > $value = "The title of the post [nid:12345]";
php > preg_match($regex, $value, $m);
php > print_r($m);
    [0] => [nid:12345]
    [1] => 12345
php >