Depends on what you are trying to do.
If you want to extract the path from a filename .. e.g. from "/home/foo/myfile.txt" you want "/home/foo" then just use the dirname function which was designed for this purpose:
$path = dirname('/home/foo/example.txt');
echo $path;
result is "/home/foo".
Another way that you can use with any delimiter, not just '/': split the string into an array (use explode); then pop the last element (use array_pop); then join the array back with your delimiter (use implode):
$items = explode('/', '/foo/bar/baz/bat');
array_pop($items); // discard last element of array (i.e. 'bat')
$result = implode('/', $items);
// $result is now '/foo/bar/baz'
The nice thing about this method is that you can also convert your delimiter along the way, if you want: e.g. you can turn '\foo\bar\baz\bat' into '/foo/bar/baz'
Another, very simple way:
$foo = '/foo/bar/baz/bat';
$result = substr($foo, 0, strrpos($foo, '/')-1);
That extracts everything before the last '/'. But you need to add code to check that strrpos doesn't return "false". BTW, note that strrpos has two 'r's - it is STRing-Reverse-POSition - not to be confused with strpos, which is STRing-POSition.
Hope that helps
PS you can also do it with regular expressions, but the above methods are easier and simpler to understand