Skip to main content
edited tags
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Source Link

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?