note 96279 modified in function.array-pop by danbrown

From: Date: Thu, 18 Feb 2010 14:06:10 +0000
Subject: note 96279 modified in function.array-pop by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166117@lists.php.net to get a copy of this message
I have used array_pop() in a function that returns the name of the current file. This can be used, for example, in conjunction with filemtime() to get the modification time of the current file. The function I coded is a one-liner: <?php function whoAmI(){ return array_pop(explode("/", $_SERVER['PHP_SELF'])); } ?> If your file URI is www.example.com/bar/foobar.php, whoAmI() will return foobar.php. To use it with e.g. filemtime() you would simply write: <?php $modtime = filemtime(whoAmI()); ?> Greetings, Jochen --was-- I have used array_pop() in a function that returns the name of the current file. This can be used, for example, in conjunction with filemtime() to get the modification time of the current file. The function I coded is a one-liner: <?php function whoAmI(){ return array_pop(explode("/", $_SERVER['PHP_SELF'])); } ?> If your file URI is www.foo.com/bar/foobar.php, whoAmI() will return foobar.php. To use it with e.g. filemtime() you would simply write: <?php $modtime = filemtime(whoAmI()); ?> Greetings, Jochen http://php.net/manual/en/function.array-pop.php

« previous php.notes (#166117) next »