Solved

extract path from file path in php

Posted on 2011-03-25
8
402 Views
Last Modified: 2012-05-11
How can I extract the path from a path to a file in php?
The path could be either UNC or local path so either \ or /
0
Comment
Question by:NewtonianB
  • 4
  • 3
8 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35220006
I putted this together,
let me know if this doenst work for you because of some other demands:

preg_match('#(.*)' . DIRECTORY_SEPARATOR . '.*$#', $_SERVER['SCRIPT_FILENAME'], $aMatch);
echo $aMatch[1];

Open in new window

0
 

Author Comment

by:NewtonianB
ID: 35220014
Thanks Rik and how would I find the directory seperator?
0
 
LVL 8

Assisted Solution

by:Rik-Legger
Rik-Legger earned 50 total points
ID: 35220021
You don't need to find it,
it is an PHP constant which is filled with the right seperator.
No need to find it out for yourselff.
Works out of the box :)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:NewtonianB
ID: 35220038
Ah ok, I just tried but it gives me back the entire path
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35220044
Can you show me the result you get?
0
 
LVL 5

Accepted Solution

by:
tsmgeek earned 450 total points
ID: 35220047
0
 

Assisted Solution

by:NewtonianB
NewtonianB earned 0 total points
ID: 35220057
fantastic tsmgeek works in all my scenarios thanks
0
 

Author Closing Comment

by:NewtonianB
ID: 35252829
thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question