WEB Reg Expression help

Discussion in 'OT Technology' started by int3rnal, Mar 3, 2008.

  1. int3rnal

    int3rnal Active Member

    Joined:
    Jun 15, 2001
    Messages:
    2,215
    Likes Received:
    0
    In php, I have a string: ./path/path/filename.txt

    I would like to strip everything before filename.txt, now I won't know what the files are named nor the extension. I'm sure this is really easy, but I'm having a hard time grasping reg expressions. Any help?
     
  2. retorq

    retorq What up bitch??

    Joined:
    Dec 14, 2006
    Messages:
    6,061
    Likes Received:
    0
    Location:
    Mohave Desert
    Explode it into an array an take the last element of the array?? It's not a one step procedure this way but I've done it before so I know it works ...
     
  3. retorq

    retorq What up bitch??

    Joined:
    Dec 14, 2006
    Messages:
    6,061
    Likes Received:
    0
    Location:
    Mohave Desert
    Hmm basename looks to be a one step way to do this:

    Code:
     [COLOR=#000000] [COLOR=#0000bb]<?php
    $path [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"/home/httpd/html/index.php"[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#0000bb]$file [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]basename[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$path[/COLOR][COLOR=#007700]);         [/COLOR][COLOR=#ff8000]// $file is set to "index.php"
    [/COLOR][COLOR=#0000bb]$file [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]basename[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$path[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]".php"[/COLOR][COLOR=#007700]); [/COLOR][COLOR=#ff8000]// $file is set to "index"
    [/COLOR][COLOR=#0000bb]?>[/COLOR][/COLOR] 
    
     
  4. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,924
    Likes Received:
    11
    Location:
    Los Angeles
    Code:
    $string = "./path/path/filename.txt";
    $filename = explode('/',$string);
    print end($filename);
    
     
  5. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,924
    Likes Received:
    11
    Location:
    Los Angeles
    ^ Going off retorq's first example.
     
  6. int3rnal

    int3rnal Active Member

    Joined:
    Jun 15, 2001
    Messages:
    2,215
    Likes Received:
    0
    Awesome, works perfectly. Thanks for the help fellas.
     

Share This Page