SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    a fresh, new start... dujmovicv's Avatar
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    retrieve file name without number

    HI ALL,

    I'm trying to do something with php but I'm not sure if it's possible at all...
    Namely, I have to retrieve a filename from the file system on the server (i.e. localhost/users/username/file_1.txt) but with NO numbers in it and without extension --> in this case I want 'file_'

    there's a simple way to get 'file_1.txt' :
    PHP Code:
    $arrStr explode("/"$_SERVER['SCRIPT_NAME'] ); 
    $arrStr array_reverse($arrStr );

    echo(
    "File name is " $arrStr[0]); 
    but I really need the file name with the number and extension 'cut off'.... Any ideas???

    Thank you guys!

    Full time ADMIN - art community
    Part time coder - dsign

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $arrStr explode("/"$_SERVER['SCRIPT_NAME'] ); 
    $arrStr array_reverse($arrStr );

    $fileName $arrStr[0];

    $strippedName preg_replace('/\d*(\..+)?/'''$fileName);

    echo 
    $strippedName

  3. #3
    a fresh, new start... dujmovicv's Avatar
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you man, that's very elegant. And what's the situation if I want to retrieve ALL the filenames (without those numbers AND extension) inside a specific folder?
    PHP Code:
    $arrStr explode("/"$_SERVER['../users/$user/$program_name/????'] ); 
    $arrStr array_reverse($arrStr );

    $fileName $arrStr[0];

    $strippedName preg_replace('/\d*(\..+)?/'''$fileName);

    echo 
    $strippedName
    Is it possible php to retrieve ???? (filenames) in a loop (for $i=0; $i<$number_of_files; $i++) ?

    Full time ADMIN - art community
    Part time coder - dsign

  4. #4
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    a fresh, new start... dujmovicv's Avatar
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the links, they were really helpful!!!!!
    Regards

    Full time ADMIN - art community
    Part time coder - dsign


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •