Reading the filename

Discussion in 'PHP' started by eWESTPost, Jan 7, 2006.

  1. #1
    Hi,
    I dunno how to parse the file name and convert the first letter in php.
    Should get 'Filename' from filename.php.
    Anyone to throw some code samples?
    Thanks in advance.
     
    eWESTPost, Jan 7, 2006 IP
  2. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are several ways you can do this, some probably much more elegant than this. This should work even if the file isn't in the root of your site, it should also work with file extensions that are longer or different than .php. I haven't tested for any other possible snags like hyphenated filenames, etc.
    echo ucwords( substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") +1, strpos($_SERVER["SCRIPT_NAME"], ".") - strrpos($_SERVER["SCRIPT_NAME"], "/") - 1) );
    PHP:
     
    tflight, Jan 7, 2006 IP
  3. eWESTPost

    eWESTPost Peon

    Messages:
    158
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    tflight,
    perfect.
    Many thanks :)
     
    eWESTPost, Jan 7, 2006 IP