extract path from file path in php

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 /
NewtonianBAsked:
Who is Participating?
 
Rik-LeggerCommented:
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
 
NewtonianBAuthor Commented:
Thanks Rik and how would I find the directory seperator?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Rik-LeggerConnect With a Mentor Commented:
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
 
NewtonianBAuthor Commented:
Ah ok, I just tried but it gives me back the entire path
0
 
Rik-LeggerCommented:
Can you show me the result you get?
0
 
NewtonianBConnect With a Mentor Author Commented:
fantastic tsmgeek works in all my scenarios thanks
0
 
NewtonianBAuthor Commented:
thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.