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 /
Who is Participating?
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

NewtonianBAuthor Commented:
Thanks Rik and how would I find the directory seperator?
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 :)
NewtonianBAuthor Commented:
Ah ok, I just tried but it gives me back the entire path
Can you show me the result you get?
NewtonianBConnect With a Mentor Author Commented:
fantastic tsmgeek works in all my scenarios thanks
NewtonianBAuthor Commented:
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.