Displaying in the wrong place

Here is my index.php

<?php
header('Content-type: text/html; charset=utf-8');
$f1="index.tpl";
if (!file_exists($f1)) {
header('Content-type: text/html; charset=utf-8');
echo "<center>
<br><br>
<h1> !</h1>
</center>";
exit;
}
$f = fopen($f1,"r"); 
$site = fread($f, filesize ($f1)); 
fclose ($f);
require_once "menu_admin.php";
$site=str_replace('{menu}',$menu,$site);
echo "{$site}";
exit;
?>

And here is index.tpl (template)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{TITLE}</title>
<style type="text/css"> 
<head>
<body class="thrColHybHdr">
<div id="container">
  <div id="header">
<center>
    <img src="https://www.igodkb.ru/templates/IGODKBv3/images/logo.gif">
</center> 
  <!-- end #header --></div>
  <div id="menu">
  {menu}
  </div>
    <p></p>
    <!-- end #mainContent --></div>
    <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  <div id="footer">
    <p></p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>

Why is my menu showing in the wrong place? In the vverzhu and not under the cap?


Answer 1, authority 100%

The menu was not written to the $menu variable and the string didn’t work as a result

$site=str_replace('{menu}',$menu,$site);

and the menu was just written before the template.