Php 分析错误:语法错误,意外'&燃气轮机';,期望函数(T_函数)或常数(T_常数)

Php 分析错误:语法错误,意外'&燃气轮机';,期望函数(T_函数)或常数(T_常数),php,Php,我一直在犯错误 分析错误:语法错误,意外“?>”,应为函数 (T_函数)或常数(T_常数) 从我读到的内容来看,这通常指向一个缺失的“}”,但无论我读了多少遍,所有内容似乎都是匹配的。我还尝试删除其中一个“}”,以防有太多的“}”,但它返回了错误` 分析错误:语法错误,意外的文件结尾 ` 这是我的密码: <?php class Post{ private $user_obj; private $con; public function __construc

我一直在犯错误

分析错误:语法错误,意外“?>”,应为函数 (T_函数)或常数(T_常数)

从我读到的内容来看,这通常指向一个缺失的“}”,但无论我读了多少遍,所有内容似乎都是匹配的。我还尝试删除其中一个“}”,以防有太多的“}”,但它返回了错误`

分析错误:语法错误,意外的文件结尾

`

这是我的密码:

<?php
class Post{ 
     private $user_obj;
     private $con;

     public function __construct($con, $user){
            $this->con = $con;
            $this->user_obj = new User($con, $user);
     }


     public function submitPost($body, $user_to) {
         $body = strip_tags($body); //removes any HTML tags             
         $body = mysqli_real_escape_string($this->con, $body); //Allows the use of " ' " so it doesn't think it's a new string. 
         $check_empty = preg_replace('/\s+/', '', $body); //Deletes all spaces

         if($check_empty != "") {


             //Current date and time
             $date_added = date("Y-m-d H:i:s");
             //Get username
             $added_by = $this->user_obj->getUsername();

             //if user is on their own profile, user_to is 'none'
             if($user_to == $added_by) {
                 $user_to = "none";
             }

             //insert post
            $query = mysqli_query($this->con, "INSERT INTO posts VALUES('', 
            '$body', '$added_by', '$user_to', '$date_added', 'no', 'no', 
            '0')");

             $returned_id = mysqli_insert_id($this->con);

             //Insert notification

             //Update post count for user
             $num_posts = $this->user_obj->getNumPosts();
             $num_posts++;
             $update_query = mysqli_query($this->con, "UPDATE users SET 
             num_posts='$num_posts' WHERE username='$added_by'");
         }
     }
?>

您未能关闭该类。请尝试此操作


之前的末尾添加一个


因为你还没有关闭你的
类帖子

。如果它在哪里,他们甚至在哪里。我想最后你错过了一个},但很难在我的手机上查到

注意:首先,您需要改变编码样式和编码模式。 看这一页


您丢失了
}
您的注释是否在代码中也被弄乱了,还是因为代码块?在我的例子中,是php版本问题。我从php7.3切换到了7.4,它成功了。希望这句话能对别人有所帮助。
    <?php
class Post{ 
     private $user_obj;
     private $con;

     public function __construct($con, $user){
            $this->con = $con;
            $this->user_obj = new User($con, $user);
}


     public function submitPost($body, $user_to) {
         $body = strip_tags($body); //removes any HTML tags
         $body = mysqli_real_escape_string($this->con, $body); //Allows the 
         use of " ' " so it doesn't think it's a new string.
         $check_empty = preg_replace('/\s+/', '', $body); //Deletes all 
         spaces

         if($check_empty != "") {


             //Current date and time
             $date_added = date("Y-m-d H:i:s");
             //Get username
             $added_by = $this->user_obj->getUsername();

             //if user is on their own profile, user_to is 'none'
             if($user_to == $added_by) {
                 $user_to = "none";
             }

             //insert post
            $query = mysqli_query($this->con, "INSERT INTO posts VALUES('', 
            '$body', '$added_by', '$user_to', '$date_added', 'no', 'no', 
            '0')");

             $returned_id = mysqli_insert_id($this->con);

             //Insert notification

             //Update post count for user
             $num_posts = $this->user_obj->getNumPosts();
             $num_posts++;
             $update_query = mysqli_query($this->con, "UPDATE users SET 
             num_posts='$num_posts' WHERE username='$added_by'");
             }
    }
}
    ?>