Optimize this path location script? Example Script is located in /home/insp/public_html/deploy/

I want to return the /home/insp/ section

$path = realpath(__DIR__);

        $parts = explode('/', $path);

        $newPath = array(
            $parts[0],
            $parts[1],
            $parts[2],
        );

        $realPath = implode('/', $newPath);


Is there a better/more effeicent way to acheve this?
A different way:

preg_match(':^/[^/]*/[^/]*/:', realpath(__DIR__), $matches);
$realPath = $matches[0];


This matches the first and second files in path, and stores them in $matches.