[Solved-4 Solutions] Parse error: Syntax error, unexpected end of file in my PHP code



Error Description:

    • We get an error:
    Parse error: syntax error, unexpected end of file in the line
    
    click below button to copy the code. By - php tutorial - team
    • With this code:
    <html>
        <?php
            function login()
            {
                // Login function code
            }
            if (login())
        {?>
    
        <h2>Welcome Administrator</h2>
        <a href=\"upload.php\">Upload Files</a>
        <br />
        <a href=\"points.php\">Edit Points Tally</a>
    
        <?php}
            else
            {
                echo "Incorrect login details. Please login";
            }
        ?>
        Some more HTML code
    </html>
    
    
    click below button to copy the code. By - php tutorial - team

    Solution 1:

      • You should avoid this (at the end of your code):
      {?>
      
      click below button to copy the code. By - php tutorial - team
      • and this:
      <?php}
      
      click below button to copy the code. By - php tutorial - team
      • You shouldn't put brackets directly close to the open/close php tag, but it separate with a space:
      { ?>
      <?php {
      
      click below button to copy the code. By - php tutorial - team
      • also avoid <? and use <?php

      Solution 2:

        • Find your php.ini file
        • then open it with your favorite editor.
          ; short_open_tag = Off ; previous value
          short_open_tag = On ; new value
          
          click below button to copy the code. By - php tutorial - team

          Solution 3:

            • Check that you closed your class.
            • For example, if you have controller class with methods, and by accident you delete the final bracket, which close whole class, you will get this error.
            class someControler{
            private $varr;
            public $varu;
            ..
            public function method {
            ..
            } 
            ..
            }// if you forget to close the controller, you will get the error
            
            click below button to copy the code. By - php tutorial - team

            Solution 4:

              • Look for a comment // that breaks the closing curly brace
              if (1==1) { //echo "it is true"; }
              
              click below button to copy the code. By - php tutorial - team

              the closing curly brace will not properly close the conditional section and php won't properly process the remainder of code.


              Related Searches to Parse error: Syntax error, unexpected end of file in my PHP