Results 1 to 10 of 10

Thread: Regex phrasing

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default Regex phrasing

    I have this code and am trying to have it display the current directory a user is in but can't get the regular expression right. I want it to read from the first / till the last / that contains a "." so /finds/all/of/this/with/slashs/ignoresthis.html

    $url = $_SERVER['REQUEST_URI'];
    $currrentdir = preg_split("/.*/.*.", $url );

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    This should do it:
    PHP Code:
    <?php
    $server 
    $_SERVER['REQUEST_URI'];
    $split_server explode('/'$server);
    unset(
    $split_server[count($split_server)-1]);

    print_r($split_sever);
    ?>
    Last edited by Nile; 05-07-2009 at 02:58 AM.
    Jeremy | jfein.net

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    That's not bringing anything up.

    I put this code in to test and the only thing that came up is "/test/OTHER/testering/admin.php "

    PHP Code:
    $server $_SERVER['REQUEST_URI'];
        
    $split_server explode('/'$server);
        unset(
    $split_server[count($split_server)-1]);
        
    print_r($split_sever);  
        echo 
    $server;
        echo 
    $split_sever
    This is the full path http://www.bluewalrus.net/test/OTHER...ring/admin.php. Thanks for your help.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    When I go there, I get invalid username/password. If you want to output them, try this:
    PHP Code:
    <?php
    $server 
    $_SERVER['REQUEST_URI'];
    $split_server explode('/'$server);
    unset(
    $split_server[count($split_server)-1]);

    echo 
    implode(" / "$split_server);
    ?>
    Jeremy | jfein.net

  5. The Following User Says Thank You to Nile For This Useful Post:

    bluewalrus (05-07-2009)

  6. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    oo that works that way. whats the difference between the two? If i set this to a value like this will it hold the same value?
    PHP Code:
    $currdir implode(" / "$split_server); 

  7. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by bluewalrus View Post
    oo that works that way. whats the difference between the two? If i set this to a value like this will it hold the same value?
    PHP Code:
    $currdir implode(" / "$split_server); 
    $split_server is an array, therefore you need to use implode() to get it back into a string for the echo.

  8. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Okay so this still isn't working for me but it is echoing the correct directory so i'm doing something else wrong.

    I'm trying to list the contents of the current directory. I don't want it to be entered already though (example of not $dir = "." I already had a script for that which didnt work. I want the php to figure out the current directory and list the contents and then later for the user to be able to change that if they want. I got part of this from php.net .

    PHP Code:
     <?php
    $server 
    $_SERVER['REQUEST_URI'];
        
    $split_server explode('/'$server);
        unset(
    $split_server[count($split_server)-1]);
        
    $curdir implode("/"$split_server);
        
    $dir $curdir;
    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
        if (
    $dh opendir($dir)) {
            while ((
    $file readdir($dh)) !== false) {
                echo 
    "filename: $file : filetype: " filetype($dir $file) . "\n";
            }
            
    closedir($dh);
        }
    }
    ?>
    Last edited by Snookerman; 05-08-2009 at 03:47 PM. Reason: added [php] tags

  9. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    So, you're trying to do something like this:
    Index.php
    Code.php
    Jeremy | jfein.net

  10. #9
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Yea, well to display that, at the time begin, if those were the only two files in the directory they were in. I don't want to list images but i think I'll be able to write limitors once i see what im missing here...

  11. #10
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Use the glob function.
    Jeremy | jfein.net

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
  •