Re: Get filename in php command line

From: Date: Tue, 17 Jul 2001 15:50:57 +0000
Subject: Re: Get filename in php command line
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-58286@lists.php.net to get a copy of this message
Seems that $PHP_SELF is not defined when it's run from the command line. Reuben D. Budiardja On Tuesday 17 July 2001 10:29 am, Jason Bell wrote: > $PHP_SELF returns the filename with the full path. from there, you can use > split to split the string wherever a / occurs, then call count, to get the > total number of values in the array, decrememnt the count by 1 (Arrays > begin at 0) then, set a variable to store just the filename, like so: > > $fullpath = split('/',$PHP_SELF); > $c = count($fullpath); > $c--; > $filename = $fullpath[$c]; > > There may be a better way to do it, but this works for me, and it's only 4 > lines. :) > > JB > > > ----- Original Message ----- > From: "Reuben D Budiardja" <reubendb@goshen.edu> > To: <php-general@lists.php.net> > Sent: Tuesday, July 17, 2001 7:48 AM > Subject: [PHP] Get filename in php command line > > > > Hello, > How do I get the filename or script name if I run it in php comamnd line? > For > example, if I run this > > bash$ php test.php > > I want to get something inside test.php that tells me the filename is > test.php, but *without* the actual path. > > Thanks > Reuben D. Budiardja >

« previous php.general (#58286) next »