Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-24-2003, 04:50 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
regex match help please

i'm making a script that walks through directories..

i have it going up through directories and reading fine, .. but the problem is coming back down.

../ is not an option in this script.

what i need to do is use regular expressions 'preg_replace()' to take off the last directory of the path string.
PHP Code:
<?
$path
="./path/to/somwhere/";

// here i need a function to modify the path
// to be: ./path/to/
?>
a regular expression would do the trick, but i'm not sure how to approach matching the last part of the string.
__________________
Mike
sde is offline   Reply With Quote
Old 06-24-2003, 06:31 PM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
this looks like a job for strrpos() and substr() to me.
joe_bruin is offline   Reply With Quote
Old 06-24-2003, 06:50 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
i dont' think the matching capabilities are there for that combination. i've used strstr,strpos,&substr extensivily in other scripts, .. but i need to cut everything after the second to last forward slash out.

that is why i thought i needed regext .. so i could match the end of the string to the second slash back.
__________________
Mike
sde is offline   Reply With Quote
Old 06-24-2003, 08:22 PM   #4 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
you've got all the tools. just put them together.
untested, off the top of my head:

PHP Code:
<?
  $s 
"/the/path/removeme/";

  
$s substr($s0strrpos($s"/"));  // removes last slash
  
$s substr($s0strrpos($s"/") + 1);  // removes "removeme"

?>
joe_bruin is offline   Reply With Quote
Old 06-24-2003, 08:32 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
very cool =) thanks a lot.

i didn't think to use it twice like that.

i really apprecaite it .. it works like a charm.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search -That Can Match Out Of Order Items JBurke All Other Coding Languages 11 09-25-2003 03:09 PM
preg_replace regex question sde PHP 4 09-18-2002 11:23 AM
regex? sde PHP 4 07-02-2002 05:40 PM


All times are GMT -8. The time now is 02:05 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting