Q:

How to set dynamic titles in one page template embedding different pages inside the body tag - PHP

According to single page template structure there's only one file called index.php that embeds pages in it using PHP function include_once() inside the body tag against the query string $_GET['page'] 
<?php $page = $_GET['page']; ?>
<html>
   <head>
      <title>
         <!-- title needs to update according to page here -->
      </title>
   </head>
   <body>
      <?php  require_once MC_ROOT.'/pages/'.$page.'.php'; // page content goes here like: <div> [CONTENT], <h1> [PRODUCT TITLE] </h1> </div> etc... ?>
   </body>
</html>

How do i set dynamic titles inside <title></title> tags which comes before for each page? Pages are supposed to be home, product, contact, about etc. Please suggest any best practice. Thank you

A:

you can use pars_url(This function parses a URL)
for exam
if you address like this 
$url = "http://www.ibm.com/product?id=1";
echo parse_url($url, PHP_URL_PATH);
////echo product /////

OR
$url = 'http://www.ibm.com/product/il.php?id=value';
$var  = parse_url($url, PHP_URL_PATH);
$var  = explode('/', $url);
echo $var[3];
///echo product////

OR
$url = 'http://www.ibm.com/aboutUs.php';
$var  = parse_url($url, PHP_URL_PATH);
$var  = explode('/', $url);
$var = str_replace(".php","",$var[3]);
echo $var;
///echo aboutUs////

