you could explode into an array
and make an [man]array_pop[/man], into $dir
and then implode the rest into a $path
<?php
$string = $directory = "/something/to/this/dir";
// remove any leading or trailing '/'
$string = trim($string, '/');
// $bits is an array with every part
$bits = explode( '/', $string );
// TEST display array
echo '<pre>'.print_r($bits,true).'</pre>';
// pop last bit into $dir
$dir = array_pop($bits);
// implode the rest into path string again
// adding a '/' in front
$path = '/'.implode('/', $bits);
echo 'path= '.$path;
echo '<br>';
echo 'dir= '.$dir;
?>