خطأ برمجي لا افهم سببه

السلام عليكم

من المفروض اني اعمل ع محرك قوالب , ومن خلال التعابير القياسية اضيف الحالة الشرطية للمحرك , هنا سطر الكود :

                // تحويل كل ما هو داخل <if con=""> الي شرط   
        $this->output = preg_replace('/<if con="(.*)"\s*>/i','<?php if($1){ ?>',$this->output);

            // إغلاق الشرط  
        $this->output = preg_replace('/<\/if>/i','<php } ?>',$this->output);

لكن في حالة تجربة الاداء يظهر الخطأ :

Parse error: syntax error, unexpected end of file in C:\wamp\www\ht.html on line 366

مع العلم ان السطر 36 في الاصل هو وسم اغلاق الـ html

فهل من اي تفسير !؟


وانا ايضا اعاني من نفس المشكله لا افهم سبب ظهورها لي في كل مره

خطا في وسم اغلاق html

<?php

require_once 'php_action/db_connect.php';

session_start();



$errors=array();



if($_POST){

    $username = $_POST['$username'];

    $password = $_POST['$password'];



if(empty($username) || empty($password)) {

    if($username == "") {

        $errors[] = "Username is required";

    } 



    if($password == "") {

        $errors[] = "Password is required";

    }

}else{

    $sql="SELECT * FORM users WHERE username = '$username'";

    $result = $connect->query($sql);



    if($result->num_rows==1){

        $password = md5($password);



        $mainsql = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";

        $mainResult = $connect->query($mainsql);



        if($mainResult->num_rows == 1){

            $value = $mainResult->fetch_assoc();

            $user_id = $value['user_id'];



            $_SESSION['userId'] = $user_id;

            header('location:
        } else{

            $errors[] = "Incorrect username/password combination";

        }

    }else{

        $errors[] = "Username dosnot exists";

    }

}

?>

<!DOCTYPE html>

<title>Stock Management System</title>
<!-- bootstrap -->

<link rel="stylesheet" href="assests/bootstrap/css/bootstrap.min.css">

<!-- bootstrap theme-->

<link rel="stylesheet" href="assests/bootstrap/css/bootstrap-theme.min.css">

<!-- font awesome -->

<link rel="stylesheet" href="assests/font-awesome/css/font-awesome.min.css">

<!-- custom css -->

<!-- jquery -->

<script src="assests/jquery/jquery.min.js"></script>

<!-- jquery ui -->

<!-- bootstrap js -->

<script src="assests/bootstrap/js/bootstrap.min.js"></script>
    <div class="row vertical">

        <div class="col-md-5 col-md-offset-4">

        <div class="panel panel-info">

                        <div class="panel-heading">

                    <h3 class="panel-title">الرجاء تسجيل الدخول</h3>

                </div>

  <div class="panel-body">

            <div class="messages">

                        <?php if($errors) {

                            foreach ($errors as $key => $value) {

                                echo '<div class="alert alert-warning" role="alert">

                                <i class="glyphicon glyphicon-exclamation-sign"></i>

                                '.$value.'</div>';                                      

                                }

                            } ?>

                    </div>



                    <form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" id="loginForm">

                        <fieldset>

                          <div class="form-group">

                                <label for="username" class="col-sm-2 control-label" dir="rtl" lang="ar">اسم المستخدم</label>

                                <div class="col-sm-10">

                                  <input type="text" class="form-control" id="username" name="username" placeholder="اسم المستخدم" autocomplete="off" />

                                </div>

                            </div>

                            <div class="form-group">

                                <label for="password" class="col-sm-2 control-label" dir="rtl" lang="ar">كلمة المرور</label>

                                <div class="col-sm-10">

                                  <input type="password" class="form-control" id="password" name="password" placeholder="كلمة المرور" autocomplete="off" />

                                </div>

                            </div>                              

                            <div class="form-group">

                                <div class="col-sm-offset-2 col-sm-10">

                                  <button type="submit" class="btn btn-default"> <i class="glyphicon glyphicon-log-in"></i> تسجيل</button>

                                </div>

                            </div>

                        </fieldset>

                    </form>

   </div>

 </div>

            </div>

        </div>

    </div>

</div>