SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2010
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stumped on a PCRE for use in PHP class

    I am trying to match the portion of this string after the last forward slash:
    PHP Code:
    '/MyPHPWorkingScripts/nextprevbutton/test_page_01.php' 
    so, in this case I would want to match 'test_page_01.php'.
    I've tried using so many patterns but they all match the whole thing, not the part after the last forward slash, even if I use lazy quantifiers.
    I use this one
    PHP Code:
    '#/.*?\Z#' 
    That should match everything between the last forward slash and the end of the string, because it's the lazy quantifier, but it doesn't. Can someone please explain why that pattern doesn't work. Thanks.

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    There's a function for that.

    basename('/MyPHPWorkingScripts/nextprevbutton/test_page_01.php')

    If you really want a regex, ask for the series of non-slash characters at the end of the string.

    ~[^/]+$~
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2010
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks very much, basename() is the perfect solution.


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
  •