FUDforum - خوراک RDF
http://fudforum.org/forum/index.php
PHP script to get name of file which houses the script?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=184997&th=123428#msg_184997
<?php
$file_name='mtg10.php';
include 'format_date.php';
?>
The included PHP script uses $file_name to get the last uploaded time stamp of the named file and process it into a displayable line. All that works as intended.
What I don't like is the need for $file_name='mtg10.php'; It would be much handier if I could write something like $file_name=getNameOfThisFile(); instead.
I've looked, can't find any such function, but maybe I haven't looked in the right references. Is there such a function or a sequence of function calls to produce that effect?
Bob Netzlof]]>rnetzlof2014-02-23T19:47:04-00:00Re: PHP script to get name of file which houses the script?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=184998&th=123428#msg_184998
rnetzlof@gmail.com:
> I have a number of files which contain PHP scripts like:
>
> <?php
> $file_name='mtg10.php';
> include 'format_date.php';
> ?>
>
> The included PHP script uses $file_name to get the last uploaded time stamp of the named file and process it into a displayable line. All that works as intended.
>
> What I don't like is the need for $file_name='mtg10.php'; It would be much handier if I could write something like $file_name=getNameOfThisFile(); instead.
>
> I've looked, can't find any such function, but maybe I haven't looked in the right references. Is there such a function or a sequence of function calls to produce that effect?
--
Christian Stadler]]>Christian Stadler2014-02-23T20:30:35-00:00Re: PHP script to get name of file which houses the script?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185001&th=123428#msg_185001
rnetzlof@gmail.com wrote:
> I have a number of files which contain PHP scripts like:
>
> <?php
> $file_name='mtg10.php';
> include 'format_date.php';
> ?>
>
> The included PHP script uses $file_name to get the last uploaded time
> stamp of the named file and process it into a displayable line. All
> that works as intended.
>
> What I don't like is the need for $file_name='mtg10.php'; It would be
> much handier if I could write something like
> $file_name=getNameOfThisFile(); instead.
>
> I've looked, can't find any such function, but maybe I haven't looked
> in the right references. Is there such a function or a sequence of
> function calls to produce that effect?
Well, there is no such function, AFAICT, but a "magic" constant:
__FILE__[1].
--
Christoph M. Becker]]>Christoph Michael Bec2014-02-23T20:34:32-00:00Re: PHP script to get name of file which houses the script?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185002&th=123428#msg_185002
> What I don't like is the need for $file_name='mtg10.php'; It would be
> much handier if I could write something like
> $file_name=getNameOfThisFile(); instead.
Make sure you read the manual page before using it, as it's quite likely
not going to give exactly the same value as "$file_name =
string_literal;" will.
--
Denis McMahon, denismfmcmahon@gmail.com]]>Denis McMahon2014-02-23T20:40:25-00:00Re: PHP script to get name of file which houses the script?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185007&th=123428#msg_185007
rnetzlof@gmail.com wrote:
>
> I have a number of files which contain PHP scripts like:
>
> <?php
> $file_name='mtg10.php';
> include 'format_date.php';
> ?>
<?php
/* __FILE__ is the full pathname of the current file. basename() returns
* the tail.
*/
$file_name=basename(__FILE__);
include 'format_date.php';
?>
>
> The included PHP script uses $file_name to get the last uploaded time stamp of the named file and process it into a displayable line. All that works as intended.
>
> What I don't like is the need for $file_name='mtg10.php'; It would be much handier if I could write something like $file_name=getNameOfThisFile(); instead.
>
> I've looked, can't find any such function, but maybe I haven't looked in the right references. Is there such a function or a sequence of function calls to produce that effect?
>
> Bob Netzlof
>
--
Robert Heller -- 978-544-6933 / heller@deepsoft.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments]]>Robert Heller2014-02-23T21:00:22-00:00Re: PHP script to get name of file which houses the script?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185011&th=123428#msg_185011
> I have a number of files which contain PHP scripts like:
>
> <?php
> $file_name='mtg10.php';
> include 'format_date.php';
> ?>
Yes $file_name=basename(__FILE__); does just what I wanted. Thanks to all who replied.