Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #12895 > unrolled thread

PHP script to get name of file which houses the script?

Started byrnetzlof@gmail.com
First post2014-02-23 11:47 -0800
Last post2014-02-23 13:57 -0800
Articles 6 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  PHP script to get name of file which houses the script? rnetzlof@gmail.com - 2014-02-23 11:47 -0800
    Re: PHP script to get name of file which houses the script? Christian Stadler <stadli@gmx.de> - 2014-02-23 21:30 +0100
    Re: PHP script to get name of file which houses the script? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-23 21:34 +0100
    Re: PHP script to get name of file which houses the script? Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-23 20:40 +0000
    Re: PHP script to get name of file which houses the script? Robert Heller <heller@deepsoft.com> - 2014-02-23 15:00 -0600
    Re: PHP script to get name of file which houses the script? rnetzlof@gmail.com - 2014-02-23 13:57 -0800

#12895 — PHP script to get name of file which houses the script?

Fromrnetzlof@gmail.com
Date2014-02-23 11:47 -0800
SubjectPHP script to get name of file which houses the script?
Message-ID<ff08231b-69c6-4fe5-b0c1-e9870fe3352f@googlegroups.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?

Bob Netzlof

[toc] | [next] | [standalone]


#12896

FromChristian Stadler <stadli@gmx.de>
Date2014-02-23 21:30 +0100
Message-ID<530a5a69$0$9523$9b4e6d93@newsspool1.arcor-online.net>
In reply to#12895
Am 23.02.2014 20:47, schrieb 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?

http://www.php.net/manual/en/language.constants.predefined.php should
answer your question.

-- 
Christian Stadler

[toc] | [prev] | [next] | [standalone]


#12899

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2014-02-23 21:34 +0100
Message-ID<530a5b55$0$9517$9b4e6d93@newsspool1.arcor-online.net>
In reply to#12895
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].

[1] <http://www.php.net/manual/en/language.constants.predefined.php>

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#12900

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-02-23 20:40 +0000
Message-ID<ledmbp$slf$2@dont-email.me>
In reply to#12895
On Sun, 23 Feb 2014 11:47:04 -0800, rnetzlof wrote:

> 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.

is this:

$file_name = __FILE__;

what you're looking for?

http://www.php.net/manual/en/language.constants.predefined.php

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

[toc] | [prev] | [next] | [standalone]


#12905

FromRobert Heller <heller@deepsoft.com>
Date2014-02-23 15:00 -0600
Message-ID<-J6dndmNX_H7_JfOnZ2dnUVZ_hGdnZ2d@giganews.com>
In reply to#12895
At Sun, 23 Feb 2014 11:47:04 -0800 (PST) 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


                                                                                               

[toc] | [prev] | [next] | [standalone]


#12909

Fromrnetzlof@gmail.com
Date2014-02-23 13:57 -0800
Message-ID<4d202693-425b-44a7-8803-167c68e17701@googlegroups.com>
In reply to#12895
On Sunday, February 23, 2014 2:47:04 PM UTC-5, rnet...@gmail.com wrote:
> 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.

Bob Netzlof

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web