Apr 23, 2006
My Digital Life Editorial Team

PHP Parse Error: syntax error, unexpected $end

In PHP 5, the following error may appears as an error entry in Apache error log or simply displays on PHP web page, even if calling to php scripts with php_info() works perfectly and successfully returns information on PHP configurations:

Parse Error: syntax error, unexpected $end in ….. scripts.php on line …

The error may caused by a missing curly bracket in PHP script coding. Beside, it may also caused by error in PHP coding in class definition, as in PHP, a class definition cannot be broke up and distributed into multiple files, or into multiple PHP blocks, unless the break is within a method declaration.

But more commonly, the error is often caused by the use of Short Open tags in PHP,

To use short open tags, it must be enabled in PHP.INI. Search for short_open_tag in PHP.INI, and change the value to On. The line should look line:

short_open_tag = On

38 Comments

  • Thanks, this fixed a huge snafu for me.

  • Thankyou for this post! saved me a lot of time!

  • Man, you saved my day :D . Tnx

  • thanks , it helped me lot….

  • Thank for good help.

  • Hey,

    I had the same error response “PHP Parse Error: syntax error, unexpected $end”. The thing was my code was perfect, everything. I was so puzzled.

    I found the answer and figured I would care it will the community:)

    Turns out PHP parses ?> even in comments.
    Example: // If query has characters like /?>|`,. ect remove them

    That was one of my comments but I fixed it with the following
    /* If query has characters like /?>|`,. ect remove them */

    Anyway like I said somebody might find this comment useful. I spend an hours going through my code.

    Peace!

    /* If query has characters like /?>|`,. ect remove them

  • thank u ! great help ..

  • it should be in everyone’s best practice to put <?php instead of <? in all your code.

  • Thanks, this solved a very puzzling problem for me!

  • Thanks a lot, it also worked for me ..:)

  • good..

  • Didn't know that the error does also come up for short tags when they aren't allowed. Thanks!

  • THANKS MAN…..

    You r smart….and honest :)

  • Thanks for this – it was a missing curly bracket for me :)

  • Thanks man …..

    you saved my lot of time….

    Thank u very much and keep posting

  • this error

    syntax error, unexpected $end in /home/lisainc/public_html/StitchTogether/includes/application_top.php on line 21

    the line 21 is

    {

    exit('Server Requirement Error: register_globals is disabled in your PHP configuration. This

    can you help?

  • thank you for your tutorial

  • Thanks for the post. The short_open_tag response solved a problem for me.

  • Terrific

    This is clearly an oldie but a goodie

    You've just helped me out no end

    Thanks !

  • 3 years later, I found the real problem. Somewhere in the code is written %>, like in a table .

    If your asp_tags = On, in ASP it means closing. It's amongst your HTML code. I got many hours to solve this problem.

  • Thanks Buddy your information helped me from hell of headache(spcly whn the code is not written by youself and u have to make your changes into it..phewww)….but thanks your suggestions helped me to locate and remove errors…..making <? to <?php solved my prob..:)

  • Also, some Webserver does not support the tag <? for php files, change them to <?php and it can work. (Dar Es Salaam, Tanzania)

  • It was very much helpful in solving my problem of the same kind of error.

  • Thank you for this awesome tip about short_open_tags! Would have never found that by myself.

  • Rana, any source code editor that supports Find / Replace with Regular Expressions can help you balance braces.

    Example: in Macrodobe Dreamweaver (any non-absolutely-ancient version), do [Ctrl]+[F] to activate Find/Replace, tell it:

    Find in: Current Document

    Search: Source Code

    Find: [{}]

    Replace: (leave blank)

    Options: “Use Regular Expression” checked, all others unchecked.

    Then simply do Find Next. This will find both opening and closing braces. For each opening brace you find, count them starting at 1. For each closing brace, subtract 1 from the current count. You should wind up at 0 just before it wraps around back to the beginning (also in any specific function, block, etc.).

    E.g.

    <code>foreach ($array as $value) { // 1

    if ($value > 100) { // 2

    echo "$value too big!
    ";

    } // 1

    } // 0</code>

  • Thank you very much …..

  • Thank you,

    Been searching for ages for solution to this.

    short_open_tag = On solved that problem for me.

    Finally I can open templates

  • syntax error, unexpected $end in C:wampwwwlogin.php on line 49

  • Thanks for your time, But for me Its really didfficult to find a missing curly bracket.

    Is there any easiest way to findout with MISSING CURLY BRACKET. Any editor can do it for us.

    Please Help.

    Rana

  • Very useful, thanks. I just upgraded to openSuse 10.3 from 10.2 which had reset my php.ini.

  • wow! thanks for your useful guidance…

  • thhanx a lot short_open_tag = On solved my problem. ypu are helpful

  • Thanks a ton, I've been trying to figure this out for the last few hours.

  • This might be due to a missing quote also

  • Hello. I have a problem with a PHP file that shows the "PHP Parse Error: syntax error, unexpected $end" error and I followed the instructions in this page and corrected the php.ini from OFF to ON.

    Now, the file don't give any feedback when I open it. It only gives me a blank page and no info! O_o

    It's strange… Can you help me please? Thanks.

  • I saw your posting and made the change to the php.ini file and I'm still getting the error the is being run with Fedora Core 5 with MySql 5.

    Can someone please help

    0)

    {

    while ($row = mysql_fetch_assoc($result))

    {

    print $row('cust_id') . '-' . $row('cust_url_desc') ;

    }

    }

    else

    {

    echo 'No rows found!';

    }

    mysql_free_result($result);

    mysql_close($connection);

    ?>

  • Thanks for this post…saved me a lot of time!

  • thanks a lot,

    short_open_tag = On solved that problem for me

Leave a comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Subscribe

Free email subscriptions
Get latest updates in email for free:

Translate This Page