Log in

View Full Version : Regex phrasing



bluewalrus
05-06-2009, 12:36 AM
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 );

Nile
05-06-2009, 01:19 AM
This should do it:


<?php
$server = $_SERVER['REQUEST_URI'];
$split_server = explode('/', $server);
unset($split_server[count($split_server)-1]);

print_r($split_sever);
?>

bluewalrus
05-06-2009, 12:51 PM
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 "


$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/testering/admin.php. Thanks for your help.

Nile
05-07-2009, 02:57 AM
When I go there, I get invalid username/password. If you want to output them, try this:


<?php
$server = $_SERVER['REQUEST_URI'];
$split_server = explode('/', $server);
unset($split_server[count($split_server)-1]);

echo implode(" / ", $split_server);
?>

bluewalrus
05-07-2009, 03:43 AM
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?


$currdir = implode(" / ", $split_server);

boogyman
05-07-2009, 04:40 AM
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?


$currdir = implode(" / ", $split_server);

$split_server is an array, therefore you need to use implode() (http://php.net/implode) to get it back into a string for the echo.

bluewalrus
05-08-2009, 03:28 PM
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
$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);
}
}
?>

Nile
05-08-2009, 09:35 PM
So, you're trying to do something like this:


Index.php
Code.php

bluewalrus
05-09-2009, 07:09 AM
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...

Nile
05-10-2009, 04:07 AM
Use the glob function.