用php动态组合页面

So, I am building a website with two languages and I am using php to put together header, footer, and template. I have this code which is doing it:

$lang = "en"; //name of a folder
$section = "start"; //name of a template in "en" folder

$content = explode("/", $_SERVER['REQUEST_URI']); // for example, www.example.en/folder/en/template

$url = $content[3];

if (!empty($content[2]) && (in_array($content[2], $languages))) { $lang = $content[2]; }
if (!empty($content[3]) && (in_array($content[3], $sections))) { $section = $content[3]; } //

$sectionTitles = $sectionTitles[$lang];

require_once ("header.php");
require_once ("templates/$lang/$section.php");
require_once ("footer.php");

I have question: how do I have to modify this code in order to use subfolder under $lang (en in this example) folder? For example, www.example.en/folder/en/blogentries/template ?

Thank you in advance!

With a help from @Mohammad I did the following:

if(sizeof($content) == 5){

    $url = $content[4];

    if (!empty($content[2]) && (in_array($content[2], $languages))) { $lang = $content[2];}
    if (!empty($content[4]) && (in_array($content[4], $sections))) { $section = $content[4];}

    require_once ("header.php");
    require_once ("templates/$lang/subfolder/$section.php");
    require_once ("footer.php");
} else {

    $url = $content[3];

    if (!empty($content[2]) && (in_array($content[2], $languages))) { $lang = $content[2];}
    if (!empty($content[3]) && (in_array($content[3], $sections))) { $section = $content[3];}

    require_once ("header.php");
    require_once ("templates/$lang/$section.php");
    require_once ("footer.php");
}

Hope this helps somebody else too.